1 views_plugin_display.inc views_plugin_display::get_plugin($type = 'style', $name = NULL)

Get the instance of a plugin, for example style or row.

Parameters

string $type: The type of the plugin.

string $name: The name of the plugin defined in hook_views_plugins.

Return value

views_plugin|FALSE:

File

core/modules/views/plugins/views_plugin_display.inc, line 841
Contains the base display plugin.

Class

views_plugin_display
The default display plugin handler. Display plugins handle options and basic mechanisms for different output methods.

Code

function get_plugin($type = 'style', $name = NULL) {
  static $cache = array();
  if (!isset($cache[$type][$name])) {
    switch ($type) {
      case 'style':
      case 'row':
        $option_name = $type . '_plugin';
        $options = $this->get_option($type . '_options');
        if (!$name) {
          $name = $this->get_option($option_name);
        }

        break;
      case 'query':
        $views_data = views_fetch_data($this->view->base_table);
        $name = !empty($views_data['table']['base']['query class']) ? $views_data['table']['base']['query class'] : 'views_query';
      default:
        $option_name = $type;
        $options = $this->get_option($type);
        if (!$name) {
          $name = $options['type'];
        }

        // access & cache store their options as siblings with the
        // type; all others use an 'options' array.
        if ($type != 'access' && $type != 'cache') {
          $options = $options['options'];
        }
    }
    $plugin = views_get_plugin($type, $name);

    if (!$plugin) {
      return;
    }
    if ($type != 'query') {
      $plugin->init($this->view, $this->display, $options);
    }
    else {
      $display_id = $this->is_defaulted($option_name) ? $this->display->id : 'default';
      $plugin->localization_keys = array($display_id, $type);

      if (!isset($this->base_field)) {
        $views_data = views_fetch_data($this->view->base_table);
        $this->view->base_field = !empty($views_data['table']['base']['field']) ? $views_data['table']['base']['field'] : '';
      }
      $plugin->init($this->view->base_table, $this->view->base_field, $options);
    }
    $cache[$type][$name] = $plugin;
  }

  return $cache[$type][$name];
}