trait FilteredPluginManagerTrait
Same name in other branches
- 9 core/lib/Drupal/Core/Plugin/FilteredPluginManagerTrait.php \Drupal\Core\Plugin\FilteredPluginManagerTrait
- 10 core/lib/Drupal/Core/Plugin/FilteredPluginManagerTrait.php \Drupal\Core\Plugin\FilteredPluginManagerTrait
- 11.x core/lib/Drupal/Core/Plugin/FilteredPluginManagerTrait.php \Drupal\Core\Plugin\FilteredPluginManagerTrait
Provides a trait for plugin managers that allow filtering plugin definitions.
Hierarchy
- trait \Drupal\Core\Plugin\FilteredPluginManagerTrait uses \Drupal\Core\Plugin\Context\ContextAwarePluginManagerTrait
4 files declare their use of FilteredPluginManagerTrait
- BlockManager.php in core/
lib/ Drupal/ Core/ Block/ BlockManager.php - ConditionManager.php in core/
lib/ Drupal/ Core/ Condition/ ConditionManager.php - FilteredPluginManagerTraitTest.php in core/
tests/ Drupal/ Tests/ Core/ Plugin/ FilteredPluginManagerTraitTest.php - LayoutPluginManager.php in core/
lib/ Drupal/ Core/ Layout/ LayoutPluginManager.php
File
-
core/
lib/ Drupal/ Core/ Plugin/ FilteredPluginManagerTrait.php, line 12
Namespace
Drupal\Core\PluginView source
trait FilteredPluginManagerTrait {
use ContextAwarePluginManagerTrait;
/**
* Implements \Drupal\Core\Plugin\FilteredPluginManagerInterface::getFilteredDefinitions().
*/
public function getFilteredDefinitions($consumer, $contexts = NULL, array $extra = []) {
if (!is_null($contexts)) {
$definitions = $this->getDefinitionsForContexts($contexts);
}
else {
$definitions = $this->getDefinitions();
}
$type = $this->getType();
$hooks = [];
$hooks[] = "plugin_filter_{$type}";
$hooks[] = "plugin_filter_{$type}__{$consumer}";
$this->moduleHandler()
->alter($hooks, $definitions, $extra, $consumer);
$this->themeManager()
->alter($hooks, $definitions, $extra, $consumer);
return $definitions;
}
/**
* A string identifying the plugin type.
*
* This string should be unique and generally will correspond to the string
* used by the discovery, e.g. the annotation class or the YAML file name.
*
* @return string
* A string identifying the plugin type.
*/
protected abstract function getType();
/**
* Wraps the module handler.
*
* @return \Drupal\Core\Extension\ModuleHandlerInterface
* The module handler.
*/
protected function moduleHandler() {
if (property_exists($this, 'moduleHandler') && $this->moduleHandler instanceof ModuleHandlerInterface) {
return $this->moduleHandler;
}
return \Drupal::service('module_handler');
}
/**
* Wraps the theme manager.
*
* @return \Drupal\Core\Theme\ThemeManagerInterface
* The theme manager.
*/
protected function themeManager() {
if (property_exists($this, 'themeManager') && $this->themeManager instanceof ThemeManagerInterface) {
return $this->themeManager;
}
return \Drupal::service('theme.manager');
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overrides |
---|---|---|---|---|
ContextAwarePluginManagerTrait::contextHandler | protected | function | Wraps the context handler. | 1 |
ContextAwarePluginManagerTrait::getDefinitions | abstract public | function | See \Drupal\Component\Plugin\Discovery\DiscoveryInterface::getDefinitions(). | 1 |
ContextAwarePluginManagerTrait::getDefinitionsForContexts | public | function | See \Drupal\Core\Plugin\Context\ContextAwarePluginManagerInterface::getDefinitionsForContexts(). | |
FilteredPluginManagerTrait::getFilteredDefinitions | public | function | Implements \Drupal\Core\Plugin\FilteredPluginManagerInterface::getFilteredDefinitions(). | |
FilteredPluginManagerTrait::getType | abstract protected | function | A string identifying the plugin type. | 4 |
FilteredPluginManagerTrait::moduleHandler | protected | function | Wraps the module handler. | 1 |
FilteredPluginManagerTrait::themeManager | protected | function | Wraps the theme manager. | 1 |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.