Chris@0: setCacheBackend($cache_backend, "views:$handler_type"); Chris@0: $this->alterInfo('views_plugins_' . $handler_type); Chris@0: Chris@0: $this->viewsData = $views_data; Chris@0: $this->handlerType = $handler_type; Chris@0: $this->defaults = [ Chris@0: 'plugin_type' => $handler_type, Chris@0: ]; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Fetches a handler from the data cache. Chris@0: * Chris@0: * @param array $item Chris@0: * An associative array representing the handler to be retrieved: Chris@0: * - table: The name of the table containing the handler. Chris@0: * - field: The name of the field the handler represents. Chris@0: * @param string|null $override Chris@0: * (optional) Override the actual handler object with this plugin ID. Used for Chris@0: * aggregation when the handler is redirected to the aggregation handler. Chris@0: * Chris@0: * @return \Drupal\views\Plugin\views\ViewsHandlerInterface Chris@0: * An instance of a handler object. May be a broken handler instance. Chris@0: */ Chris@0: public function getHandler($item, $override = NULL) { Chris@0: $table = $item['table']; Chris@0: $field = $item['field']; Chris@0: // Get the plugin manager for this type. Chris@0: $data = $this->viewsData->get($table); Chris@0: Chris@0: if (isset($data[$field][$this->handlerType])) { Chris@0: $definition = $data[$field][$this->handlerType]; Chris@0: foreach (['group', 'title', 'title short', 'label', 'help', 'real field', 'real table', 'entity type', 'entity field'] as $key) { Chris@0: if (!isset($definition[$key])) { Chris@0: // First check the field level. Chris@0: if (!empty($data[$field][$key])) { Chris@0: $definition[$key] = $data[$field][$key]; Chris@0: } Chris@0: // Then if that doesn't work, check the table level. Chris@0: elseif (!empty($data['table'][$key])) { Chris@0: $definition_key = $key === 'entity type' ? 'entity_type' : $key; Chris@0: $definition[$definition_key] = $data['table'][$key]; Chris@0: } Chris@0: } Chris@0: } Chris@0: Chris@0: // @todo This is crazy. Find a way to remove the override functionality. Chris@0: $plugin_id = $override ?: $definition['id']; Chris@0: // Try to use the overridden handler. Chris@0: $handler = $this->createInstance($plugin_id, $definition); Chris@0: if ($override && method_exists($handler, 'broken') && $handler->broken()) { Chris@0: $handler = $this->createInstance($definition['id'], $definition); Chris@0: } Chris@0: return $handler; Chris@0: } Chris@0: Chris@0: // Finally, use the 'broken' handler. Chris@0: return $this->createInstance('broken', ['original_configuration' => $item]); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function createInstance($plugin_id, array $configuration = []) { Chris@0: $instance = parent::createInstance($plugin_id, $configuration); Chris@0: if ($instance instanceof HandlerBase) { Chris@0: $instance->setModuleHandler($this->moduleHandler); Chris@0: $instance->setViewsData($this->viewsData); Chris@0: } Chris@0: return $instance; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getFallbackPluginId($plugin_id, array $configuration = []) { Chris@0: return 'broken'; Chris@0: } Chris@0: Chris@0: }