function views_get_handler

Fetch a handler from the data cache.

Parameters

array $item: An associative array representing the handler to be retrieved:

  • table: The name of the table containing the handler.
  • field: The name of the field the handler represents.
  • optional: (optional) Whether or not this handler is optional. If a handler is missing and not optional, a debug message will be displayed. Defaults to FALSE.

string $type: The type of handler. i.e, sort, field, argument, filter, relationship

string|null $override: (optional) Override the actual handler object with this plugin ID. Used for aggregation when the handler is redirected to the aggregation handler.

Return value

views_handler An instance of a handler object. May be views_handler_broken.

14 calls to views_get_handler()
ConfigItem::buildForm in drupal/core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/ConfigItem.php
Implements \Drupal\Core\Form\FormInterface::buildForm().
ConfigItem::submitForm in drupal/core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/ConfigItem.php
Overrides \Drupal\views_ui\Form\Ajax\ViewsFormBase::submitForm().
ConfigItemGroup::submitForm in drupal/core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/ConfigItemGroup.php
Overrides \Drupal\views_ui\Form\Ajax\ViewsFormBase::submitForm().
DisplayPluginBase::getHandlers in drupal/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php
Get a full array of handlers for $type. This caches them.
FieldUnitTest::testClickSortable in drupal/core/modules/views/lib/Drupal/views/Tests/Handler/FieldUnitTest.php
Tests whether the filters are click sortable as expected.

... See full list

File

drupal/core/modules/views/views.module, line 853
Primarily Drupal hooks and global API functions to manipulate views.

Code

function views_get_handler($item, $type, $override = NULL) {
  $table = $item['table'];
  $field = $item['field'];
  $optional = isset($item['optional']) ? $item['optional'] : FALSE;

  // Get the plugin manager for this type.
  $manager = Views::pluginManager($type);
  $data = Views::viewsData()
    ->get($table);
  if (isset($data[$field][$type])) {
    $definition = $data[$field][$type];
    foreach (array(
      'group',
      'title',
      'title short',
      'help',
      'real field',
      'real table',
    ) as $key) {
      if (!isset($definition[$key])) {

        // First check the field level
        if (!empty($data[$field][$key])) {
          $definition[$key] = $data[$field][$key];
        }
        elseif (!empty($data['table'][$key])) {
          $definition[$key] = $data['table'][$key];
        }
      }
    }

    // @todo This is crazy. Find a way to remove the override functionality.
    $plugin_id = $override ?: $definition['id'];

    // Try to use the overridden handler.
    try {
      return $manager
        ->createInstance($plugin_id, $definition);
    } catch (PluginException $e) {

      // If that fails, use the original handler.
      try {
        return $manager
          ->createInstance($definition['id'], $definition);
      } catch (PluginException $e) {

        // Deliberately empty, this case is handled generically below.
      }
    }
  }
  if (!$optional) {

    //debug(t("Missing handler: @table @field @type", array('@table' => $table, '@field' => $field, '@type' => $type)));
  }

  // Finally, use the 'broken' handler.
  return $manager
    ->createInstance('broken');
}