FilteredPluginManagerTrait.php in Drupal 8
File
core/lib/Drupal/Core/Plugin/FilteredPluginManagerTrait.php
View source
<?php
namespace Drupal\Core\Plugin;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\Context\ContextAwarePluginManagerTrait;
use Drupal\Core\Theme\ThemeManagerInterface;
trait FilteredPluginManagerTrait {
use ContextAwarePluginManagerTrait;
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;
}
protected abstract function getType();
protected function moduleHandler() {
if (property_exists($this, 'moduleHandler') && $this->moduleHandler instanceof ModuleHandlerInterface) {
return $this->moduleHandler;
}
return \Drupal::service('module_handler');
}
protected function themeManager() {
if (property_exists($this, 'themeManager') && $this->themeManager instanceof ThemeManagerInterface) {
return $this->themeManager;
}
return \Drupal::service('theme.manager');
}
}