diff --git a/search_api.plugin_type.yml b/search_api.plugin_type.yml index e2607e9..1fbd834 100644 --- a/search_api.plugin_type.yml +++ b/search_api.plugin_type.yml @@ -8,6 +8,11 @@ search_api_data_type: plugin_manager_service_id: plugin.manager.search_api.data_type plugin_definition_decorator_class: \Drupal\plugin\PluginDefinition\ArrayPluginDefinitionDecorator +search_api_display: + label: Search API display + plugin_manager_service_id: plugin.manager.search_api.display + plugin_definition_decorator_class: \Drupal\plugin\PluginDefinition\ArrayPluginDefinitionDecorator + search_api_processor: label: Search API processor plugin_manager_service_id: plugin.manager.search_api.processor @@ -17,8 +22,3 @@ search_api_tracker: label: Search API tracker plugin_manager_service_id: plugin.manager.search_api.tracker plugin_definition_decorator_class: \Drupal\plugin\PluginDefinition\ArrayPluginDefinitionDecorator - -search_api_display: - label: Search API display - plugin_manager_service_id: plugin.manager.search_api.display - plugin_definition_decorator_class: \Drupal\plugin\PluginDefinition\ArrayPluginDefinitionDecorator diff --git a/search_api.services.yml b/search_api.services.yml index 9a42b1c..61db9d4 100644 --- a/search_api.services.yml +++ b/search_api.services.yml @@ -18,6 +18,10 @@ services: class: Drupal\search_api\Datasource\DatasourcePluginManager parent: default_plugin_manager + plugin.manager.search_api.display: + class: Drupal\search_api\Display\DisplayPluginManager + parent: default_plugin_manager + plugin.manager.search_api.processor: class: Drupal\search_api\Processor\ProcessorPluginManager arguments: ['@container.namespaces', '@cache.discovery', '@module_handler', '@string_translation'] @@ -26,10 +30,6 @@ services: class: Drupal\search_api\Tracker\TrackerPluginManager parent: default_plugin_manager - plugin.manager.search_api.display: - class: Drupal\search_api\Display\DisplayPluginManager - parent: default_plugin_manager - search_api.index_task_manager: class: Drupal\search_api\Task\IndexTaskManager arguments: ['@state', '@entity_type.manager'] diff --git a/src/Annotation/SearchApiDisplay.php b/src/Annotation/SearchApiDisplay.php index af4fc24..35cb95a 100644 --- a/src/Annotation/SearchApiDisplay.php +++ b/src/Annotation/SearchApiDisplay.php @@ -37,13 +37,4 @@ class SearchApiDisplay extends Plugin { */ public $label; - /** - * The description of the display. - * - * @ingroup plugin_translatable - * - * @var \Drupal\Core\Annotation\Translation - */ - public $description; - } diff --git a/src/Display/DisplayDeriverBase.php b/src/Display/DisplayDeriverBase.php index 3912bd0..ea246e6 100644 --- a/src/Display/DisplayDeriverBase.php +++ b/src/Display/DisplayDeriverBase.php @@ -7,7 +7,6 @@ namespace Drupal\search_api\Display; - use Drupal\Core\Entity\EntityTypeManager; use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; @@ -40,11 +39,9 @@ abstract class DisplayDeriverBase implements ContainerDeriverInterface { public static function create(ContainerInterface $container, $base_plugin_id) { $deriver = new static(); - /** @var \Drupal\Core\Entity\EntityTypeManager $entity_type_manager */ $entity_type_manager = $container->get('entity_type.manager'); $deriver->setEntityTypeManager($entity_type_manager); - /** @var \Drupal\Core\StringTranslation\TranslationInterface $translation */ $translation = $container->get('string_translation'); $deriver->setStringTranslation($translation); @@ -58,7 +55,7 @@ abstract class DisplayDeriverBase implements ContainerDeriverInterface { * The entity manager. */ public function getEntityTypeManager() { - return $this->entityTypeManager ?: \Drupal::service('entity_type.manager'); + return $this->entityTypeManager; } /** diff --git a/src/Display/DisplayInterface.php b/src/Display/DisplayInterface.php index f94cfcc..8f34cd3 100644 --- a/src/Display/DisplayInterface.php +++ b/src/Display/DisplayInterface.php @@ -29,7 +29,7 @@ interface DisplayInterface extends PluginInspectionInterface, DerivativeInspecti public function label(); /** - * Retrieves the index used by this display. + * Returns the index used by this display. * * @return \Drupal\search_api\IndexInterface * The search index used by this display. @@ -37,7 +37,7 @@ interface DisplayInterface extends PluginInspectionInterface, DerivativeInspecti public function getIndex(); /** - * Returns the path used for this Display. + * Returns the path used for this display. * * @return string * The path of the display. diff --git a/src/Display/DisplayPluginBase.php b/src/Display/DisplayPluginBase.php index 01984df..83214fe 100644 --- a/src/Display/DisplayPluginBase.php +++ b/src/Display/DisplayPluginBase.php @@ -15,8 +15,8 @@ use Drupal\search_api\Plugin\IndexPluginBase; * Plugins extending this class need to define a plugin definition array through * annotation. The definition includes the following keys: * - id: The unique, system-wide identifier of the display class. - * - label: The human-readable name of the display class, translated. - * - description: The human-readable description of the display class, translated. + * - label: Human-readable name of the display class, translated. + * - description: Human-readable description of the display class, translated. * * A complete plugin definition should be written as in this example: * diff --git a/src/Display/DisplayPluginManager.php b/src/Display/DisplayPluginManager.php index 4fd8c2e..4cbed73 100644 --- a/src/Display/DisplayPluginManager.php +++ b/src/Display/DisplayPluginManager.php @@ -12,7 +12,7 @@ use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Plugin\DefaultPluginManager; /** - * Manages data type plugins. + * Manages display plugins. * * @see \Drupal\search_api\Annotation\SearchApiDisplay * @see \Drupal\search_api\Display\DisplayInterface @@ -22,6 +22,15 @@ use Drupal\Core\Plugin\DefaultPluginManager; class DisplayPluginManager extends DefaultPluginManager { /** + * Static cache for the display definitions. + * + * @var string[][] + * + * @see \Drupal\search_api\Display\DisplayPluginManager::getInstances() + */ + protected $displays; + + /** * Constructs a DisplayPluginManager object. * * @param \Traversable $namespaces @@ -37,4 +46,25 @@ class DisplayPluginManager extends DefaultPluginManager { $this->setCacheBackend($cache_backend, 'search_api_displays'); } + /** + * Returns all known displays. + * + * @return \Drupal\search_api\Display\DisplayInterface[] + * An array of display plugins, keyed by type identifier. + */ + public function getInstances() { + if (!isset($this->DataTypes)) { + $this->displays = array(); + + foreach ($this->getDefinitions() as $name => $display_definition) { + if (class_exists($display_definition['class']) && empty($this->displays[$name])) { + $display = $this->createInstance($name); + $this->displays[$name] = $display; + } + } + } + + return $this->displays; + } + } diff --git a/src/Plugin/search_api/display/ViewsPageDisplayDeriver.php b/src/Plugin/search_api/display/ViewsPageDisplayDeriver.php index 6d174e7..bf57332 100644 --- a/src/Plugin/search_api/display/ViewsPageDisplayDeriver.php +++ b/src/Plugin/search_api/display/ViewsPageDisplayDeriver.php @@ -30,7 +30,7 @@ class ViewsPageDisplayDeriver extends DisplayDeriverBase { $all_views = $views_storage->loadMultiple(); } catch (PluginNotFoundException $e) { - return []; + return array(); } if (!isset($this->derivatives[$base_plugin_id])) { @@ -47,8 +47,8 @@ class ViewsPageDisplayDeriver extends DisplayDeriverBase { $plugin_derivatives[$machine_name] = [ 'id' => $base_plugin_id . PluginBase::DERIVATIVE_SEPARATOR . $machine_name, - 'label' => $this->t('View name: %view_name. Display: %display_title', ['%view_name' => $view->label(), '%display_title' => $display_info['display_title']]), - 'description' => $this->t('Provides a display.'), + 'label' => $this->t('View %view_label, display %display_title', ['%view_name' => $view->label(), '%display_title' => $display_info['display_title']]), + 'description' => $view->get('description') ? $this->t('%view_description - Represents the page display %display_title of view %view_name.', ['%view_name' => $view->label(), '%view_description' => $view->get('description'), '%display_title' => $display_info['display_title']]) : $this->t('Represents the page display %display_title of view %view_name.', ['%view_name' => $view->label(), '%display_title' => $display_info['display_title']]), 'view_id' => $view->id(), 'view_display' => $name, ] + $base_plugin_definition;