View source
<?php
namespace Drupal\views\Plugin;
use Drupal\Component\Plugin\FallbackPluginManagerInterface;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\views\ViewsData;
use Symfony\Component\DependencyInjection\Container;
use Drupal\views\Plugin\views\HandlerBase;
class ViewsHandlerManager extends DefaultPluginManager implements FallbackPluginManagerInterface {
protected $viewsData;
protected $handlerType;
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);
$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_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,
];
}
public function getHandler($item, $override = NULL) {
$table = $item['table'];
$field = $item['field'];
$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])) {
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];
}
}
}
$plugin_id = $override ?: $definition['id'];
$handler = $this
->createInstance($plugin_id, $definition);
if ($override && method_exists($handler, 'broken') && $handler
->broken()) {
$handler = $this
->createInstance($definition['id'], $definition);
}
return $handler;
}
return $this
->createInstance('broken', [
'original_configuration' => $item,
]);
}
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;
}
public function getFallbackPluginId($plugin_id, array $configuration = []) {
return 'broken';
}
}