public function View::newDisplay

Creates a new display and a display handler instance for it.

Parameters

string $plugin_id: (optional) The plugin type from the Views plugin annotation. Defaults to 'page'.

string $title: (optional) The title of the display. Defaults to NULL.

string $id: (optional) The ID to use, e.g., 'default', 'page_1', 'block_2'. Defaults to NULL.

Return value

string|\Drupal\views\Plugin\views\display\DisplayPluginBase A new display plugin instance if executable is set, the new display ID otherwise.

File

drupal/core/modules/views/lib/Drupal/views/Plugin/Core/Entity/View.php, line 269
Definition of Drupal\views\Plugin\Core\Entity\View.

Class

View
Defines a View configuration entity class.

Namespace

Drupal\views\Plugin\Core\Entity

Code

public function newDisplay($plugin_id = 'page', $title = NULL, $id = NULL) {
  $id = $this
    ->addDisplay($plugin_id, $title, $id);

  // We can't use get() here as it will create an ViewExecutable instance if
  // there is not already one.
  if (isset($this->executable)) {
    $executable = $this
      ->get('executable');
    $executable
      ->initDisplay();
    $executable->displayHandlers
      ->addInstanceID($id);
    return $executable->displayHandlers
      ->get($id);
  }
  return $id;
}