class ViewsHandlerManager
Same name in other branches
- 9 core/modules/views/src/Plugin/ViewsHandlerManager.php \Drupal\views\Plugin\ViewsHandlerManager
- 8.9.x core/modules/views/src/Plugin/ViewsHandlerManager.php \Drupal\views\Plugin\ViewsHandlerManager
- 10 core/modules/views/src/Plugin/ViewsHandlerManager.php \Drupal\views\Plugin\ViewsHandlerManager
Plugin type manager for all views handlers.
Hierarchy
- class \Drupal\Component\Plugin\PluginManagerBase implements \Drupal\Component\Plugin\PluginManagerInterface uses \Drupal\Component\Plugin\Discovery\DiscoveryTrait
- class \Drupal\Core\Plugin\DefaultPluginManager extends \Drupal\Component\Plugin\PluginManagerBase implements \Drupal\Component\Plugin\PluginManagerInterface, \Drupal\Component\Plugin\Discovery\CachedDiscoveryInterface, \Drupal\Core\Cache\CacheableDependencyInterface uses \Drupal\Component\Plugin\Discovery\DiscoveryCachedTrait, \Drupal\Core\Cache\UseCacheBackendTrait
- class \Drupal\views\Plugin\ViewsHandlerManager extends \Drupal\Core\Plugin\DefaultPluginManager implements \Drupal\Component\Plugin\FallbackPluginManagerInterface
- class \Drupal\Core\Plugin\DefaultPluginManager extends \Drupal\Component\Plugin\PluginManagerBase implements \Drupal\Component\Plugin\PluginManagerInterface, \Drupal\Component\Plugin\Discovery\CachedDiscoveryInterface, \Drupal\Core\Cache\CacheableDependencyInterface uses \Drupal\Component\Plugin\Discovery\DiscoveryCachedTrait, \Drupal\Core\Cache\UseCacheBackendTrait
Expanded class hierarchy of ViewsHandlerManager
5 files declare their use of ViewsHandlerManager
- EntityReverse.php in core/
modules/ views/ src/ Plugin/ views/ relationship/ EntityReverse.php - LatestRevision.php in core/
modules/ views/ src/ Plugin/ views/ filter/ LatestRevision.php - LatestTranslationAffectedRevision.php in core/
modules/ views/ src/ Plugin/ views/ filter/ LatestTranslationAffectedRevision.php - ViewsHandlerManagerTest.php in core/
modules/ views/ tests/ src/ Unit/ ViewsHandlerManagerTest.php - ViewsQueryAlter.php in core/
modules/ workspaces/ src/ ViewsQueryAlter.php
1 string reference to 'ViewsHandlerManager'
- views.services.yml in core/
modules/ views/ views.services.yml - core/modules/views/views.services.yml
7 services use ViewsHandlerManager
- plugin.manager.views.area in core/
modules/ views/ views.services.yml - Drupal\views\Plugin\ViewsHandlerManager
- plugin.manager.views.argument in core/
modules/ views/ views.services.yml - Drupal\views\Plugin\ViewsHandlerManager
- plugin.manager.views.field in core/
modules/ views/ views.services.yml - Drupal\views\Plugin\ViewsHandlerManager
- plugin.manager.views.filter in core/
modules/ views/ views.services.yml - Drupal\views\Plugin\ViewsHandlerManager
- plugin.manager.views.join in core/
modules/ views/ views.services.yml - Drupal\views\Plugin\ViewsHandlerManager
File
-
core/
modules/ views/ src/ Plugin/ ViewsHandlerManager.php, line 18
Namespace
Drupal\views\PluginView source
class ViewsHandlerManager extends DefaultPluginManager implements FallbackPluginManagerInterface {
/**
* The views data cache.
*
* @var \Drupal\views\ViewsData
*/
protected $viewsData;
/**
* The handler type.
*
* @var string
*
* @see \Drupal\views\ViewExecutable::getHandlerTypes().
*/
protected $handlerType;
/**
* Constructs a ViewsHandlerManager object.
*
* @param string $handler_type
* The plugin type, for example filter.
* @param \Traversable $namespaces
* An object that implements \Traversable which contains the root paths
* keyed by the corresponding namespace to look for plugin implementations,
* @param \Drupal\views\ViewsData $views_data
* The views data cache.
* @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
* Cache backend instance to use.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler to invoke the alter hook with.
*/
public function __construct($handler_type, \Traversable $namespaces, ViewsData $views_data, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
$plugin_definition_annotation_name = 'Drupal\\views\\Annotation\\Views' . Container::camelize($handler_type);
// Special handling until all views plugins have attribute classes.
$attribute_name_candidate = 'Drupal\\views\\Attribute\\Views' . Container::camelize($handler_type);
$plugin_definition_attribute_name = class_exists($attribute_name_candidate) ? $attribute_name_candidate : Plugin::class;
$plugin_interface = 'Drupal\\views\\Plugin\\views\\ViewsHandlerInterface';
if ($handler_type == 'join') {
$plugin_interface = 'Drupal\\views\\Plugin\\views\\join\\JoinPluginInterface';
}
parent::__construct("Plugin/views/{$handler_type}", $namespaces, $module_handler, $plugin_interface, $plugin_definition_attribute_name, $plugin_definition_annotation_name);
$this->setCacheBackend($cache_backend, "views:{$handler_type}");
$this->alterInfo('views_plugins_' . $handler_type);
$this->viewsData = $views_data;
$this->handlerType = $handler_type;
$this->defaults = [
'plugin_type' => $handler_type,
];
}
/**
* Fetches a handler from the data cache.
*
* @param 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.
* @param string|null $override_plugin_id
* (optional) Override the actual handler object with this plugin ID. Used for
* aggregation when the handler is redirected to the aggregation handler.
*
* @return \Drupal\views\Plugin\views\ViewsHandlerInterface
* An instance of a handler object. May be a broken handler instance.
*/
public function getHandler(array $item, ?string $override_plugin_id = NULL) : ViewsHandlerInterface {
$table = $item['table'];
$field = $item['field'];
// Get the plugin manager for this type.
$data = $table ? $this->viewsData
->get($table) : $this->viewsData
->getAll();
if (isset($data[$field][$this->handlerType])) {
$definition = $data[$field][$this->handlerType];
foreach ([
'group',
'title',
'title short',
'label',
'help',
'real field',
'real table',
'entity type',
'entity field',
] 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 = $key === 'entity type' ? 'entity_type' : $key;
$definition[$definition_key] = $data['table'][$key];
}
}
}
// When aggregation is enabled, particular plugins need to be
// replaced in order to override the query with a query that
// can run the aggregate counts, sums, or averages for example.
// @see Drupal\views\Plugin\views\query\Sql::getAggregationInfo()
// for example which aggressively overrides any filter used
// by a number of mathematical-type queries regardless of the
// original filter.
$plugin_id = $override_plugin_id ?: $definition['id'];
// Try to use the overridden handler.
$handler = $this->createInstance($plugin_id, $definition);
if ($override_plugin_id && method_exists($handler, 'broken') && $handler->broken()) {
$handler = $this->createInstance($definition['id'], $definition);
}
return $handler;
}
// Finally, use the 'broken' handler.
return $this->createInstance('broken', [
'original_configuration' => $item,
]);
}
/**
* {@inheritdoc}
*/
public function createInstance($plugin_id, array $configuration = []) {
$instance = parent::createInstance($plugin_id, $configuration);
if ($instance instanceof HandlerBase) {
$instance->setModuleHandler($this->moduleHandler);
$instance->setViewsData($this->viewsData);
}
return $instance;
}
/**
* {@inheritdoc}
*/
public function getFallbackPluginId($plugin_id, array $configuration = []) {
return 'broken';
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|
DefaultPluginManager::$additionalAnnotationNamespaces | protected | property | Additional annotation namespaces. | ||
DefaultPluginManager::$alterHook | protected | property | Name of the alter hook if one should be invoked. | ||
DefaultPluginManager::$cacheKey | protected | property | The cache key. | ||
DefaultPluginManager::$cacheTags | protected | property | An array of cache tags to use for the cached definitions. | ||
DefaultPluginManager::$defaults | protected | property | A set of defaults to be referenced by $this->processDefinition(). | 12 | |
DefaultPluginManager::$moduleExtensionList | protected | property | The module extension list. | ||
DefaultPluginManager::$moduleHandler | protected | property | The module handler to invoke the alter hook. | 1 | |
DefaultPluginManager::$namespaces | protected | property | An object of root paths that are traversable. | ||
DefaultPluginManager::$pluginDefinitionAnnotationName | protected | property | The name of the annotation that contains the plugin definition. | ||
DefaultPluginManager::$pluginDefinitionAttributeName | protected | property | The name of the attribute that contains the plugin definition. | ||
DefaultPluginManager::$pluginInterface | protected | property | The interface each plugin should implement. | 1 | |
DefaultPluginManager::$subdir | protected | property | The subdirectory within a namespace to look for plugins. | ||
DefaultPluginManager::alterDefinitions | protected | function | Invokes the hook to alter the definitions if the alter hook is set. | 5 | |
DefaultPluginManager::alterInfo | protected | function | Sets the alter hook name. | ||
DefaultPluginManager::clearCachedDefinitions | public | function | Clears static and persistent plugin definition caches. | Overrides CachedDiscoveryInterface::clearCachedDefinitions | 11 |
DefaultPluginManager::extractProviderFromDefinition | protected | function | Extracts the provider from a plugin definition. | ||
DefaultPluginManager::findDefinitions | protected | function | Finds plugin definitions. | 7 | |
DefaultPluginManager::getCacheContexts | public | function | The cache contexts associated with this object. | Overrides CacheableDependencyInterface::getCacheContexts | |
DefaultPluginManager::getCachedDefinitions | protected | function | Returns the cached plugin definitions of the decorated discovery class. | ||
DefaultPluginManager::getCacheMaxAge | public | function | The maximum age for which this object may be cached. | Overrides CacheableDependencyInterface::getCacheMaxAge | |
DefaultPluginManager::getCacheTags | public | function | The cache tags associated with this object. | Overrides CacheableDependencyInterface::getCacheTags | |
DefaultPluginManager::getDefinitions | public | function | Gets the definition of all plugins for this type. | Overrides DiscoveryTrait::getDefinitions | 2 |
DefaultPluginManager::getDiscovery | protected | function | Gets the plugin discovery. | Overrides PluginManagerBase::getDiscovery | 16 |
DefaultPluginManager::getFactory | protected | function | Gets the plugin factory. | Overrides PluginManagerBase::getFactory | |
DefaultPluginManager::processDefinition | public | function | Performs extra processing on plugin definitions. | 14 | |
DefaultPluginManager::providerExists | protected | function | Determines if the provider of a definition exists. | 5 | |
DefaultPluginManager::setCacheBackend | public | function | Initialize the cache backend. | ||
DefaultPluginManager::setCachedDefinitions | protected | function | Sets a cache of plugin definitions for the decorated discovery class. | ||
DefaultPluginManager::useCaches | public | function | Disable the use of caches. | Overrides CachedDiscoveryInterface::useCaches | 1 |
DiscoveryCachedTrait::$definitions | protected | property | Cached definitions array. | 1 | |
DiscoveryCachedTrait::getDefinition | public | function | Overrides DiscoveryTrait::getDefinition | 3 | |
DiscoveryTrait::doGetDefinition | protected | function | Gets a specific plugin definition. | ||
DiscoveryTrait::hasDefinition | public | function | |||
PluginManagerBase::$discovery | protected | property | The object that discovers plugins managed by this manager. | ||
PluginManagerBase::$factory | protected | property | The object that instantiates plugins managed by this manager. | ||
PluginManagerBase::$mapper | protected | property | The object that returns the preconfigured plugin instance appropriate for a particular runtime condition. | ||
PluginManagerBase::getInstance | public | function | 6 | ||
PluginManagerBase::handlePluginNotFound | protected | function | Allows plugin managers to specify custom behavior if a plugin is not found. | 1 | |
UseCacheBackendTrait::$cacheBackend | protected | property | Cache backend instance. | ||
UseCacheBackendTrait::$useCaches | protected | property | Flag whether caches should be used or skipped. | ||
UseCacheBackendTrait::cacheGet | protected | function | Fetches from the cache backend, respecting the use caches flag. | ||
UseCacheBackendTrait::cacheSet | protected | function | Stores data in the persistent cache, respecting the use caches flag. | ||
ViewsHandlerManager::$handlerType | protected | property | The handler type. | ||
ViewsHandlerManager::$viewsData | protected | property | The views data cache. | ||
ViewsHandlerManager::createInstance | public | function | Overrides PluginManagerBase::createInstance | ||
ViewsHandlerManager::getFallbackPluginId | public | function | Gets a fallback id for a missing plugin. | Overrides PluginManagerBase::getFallbackPluginId | |
ViewsHandlerManager::getHandler | public | function | Fetches a handler from the data cache. | ||
ViewsHandlerManager::__construct | public | function | Constructs a ViewsHandlerManager object. | Overrides DefaultPluginManager::__construct |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.