function views_db_object::add_display

3.x view.inc views_db_object::add_display($type = 'page', $title = NULL, $id = NULL)
2.x view.inc views_db_object::add_display($type = 'page', $title = NULL, $id = NULL)

Add a new display handler to the view, automatically creating an id.

Parameters

$type: The plugin type from the views plugin data. Defaults to 'page'.

$title: The title of the display; optional, may be filled in from default.

$id: The id to use.

Return value

The key to the display in $view->display, so that the new display can be easily located.

1 call to views_db_object::add_display()
views_db_object::new_display in includes/view.inc
Create a new display and a display handler for it.

File

includes/view.inc, line 2318
Provides the view object type and associated methods.

Class

views_db_object
Base class for views' database objects.

Code

function add_display($type = 'page', $title = NULL, $id = NULL) {
  if (empty($type)) {
    return FALSE;
  }

  $plugin = views_fetch_plugin_data('display', $type);
  if (empty($plugin)) {
    $plugin['title'] = t('Broken');
  }


  if (empty($id)) {
    $id = $this->generate_display_id($type);
    if ($id !== 'default') {
      preg_match("/[0-9]+/", $id, $count);
      $count = $count[0];
    }
    else {
      $count = '';
    }

    if (empty($title)) {
      if ($count > 1) {
        $title = $plugin['title'] . ' ' . $count;
      }
      else {
        $title = $plugin['title'];
      }
    }
  }

  // Create the new display object
  $display = new views_display;
  $display->options($type, $id, $title);

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