public function View::addDisplay

Adds a new display handler to the view, automatically creating an ID.

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|false The key to the display in $view->display, or FALSE if no plugin ID was provided.

1 call to View::addDisplay()
View::newDisplay in drupal/core/modules/views/lib/Drupal/views/Plugin/Core/Entity/View.php
Creates a new display and a display handler instance for it.

File

drupal/core/modules/views/lib/Drupal/views/Plugin/Core/Entity/View.php, line 182
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 addDisplay($plugin_id = 'page', $title = NULL, $id = NULL) {
  if (empty($plugin_id)) {
    return FALSE;
  }
  $plugin = Views::pluginManager('display')
    ->getDefinition($plugin_id);
  if (empty($plugin)) {
    $plugin['title'] = t('Broken');
  }
  if (empty($id)) {
    $id = $this
      ->generateDisplayId($plugin_id);

    // Generate a unique human-readable name by inspecting the counter at the
    // end of the previous display ID, e.g., 'page_1'.
    if ($id !== 'default') {
      preg_match("/[0-9]+/", $id, $count);
      $count = $count[0];
    }
    else {
      $count = '';
    }
    if (empty($title)) {

      // If there is no title provided, use the plugin title, and if there are
      // multiple displays, append the count.
      $title = $plugin['title'];
      if ($count > 1) {
        $title .= ' ' . $count;
      }
    }
  }
  $display_options = array(
    'display_plugin' => $plugin_id,
    'id' => $id,
    'display_title' => $title,
    'position' => count($this->display),
    'display_options' => array(),
  );

  // Add the display options to the view.
  $this->display[$id] = $display_options;
  return $id;
}