diff --git a/src/Annotation/SearchApiDisplay.php b/src/Annotation/SearchApiDisplay.php index 4515c9e..0553ae5 100644 --- a/src/Annotation/SearchApiDisplay.php +++ b/src/Annotation/SearchApiDisplay.php @@ -32,4 +32,13 @@ class SearchApiDisplay extends Plugin { */ public $label; + /** + * The human-readable description for the display plugin. + * + * @ingroup plugin_translatable + * + * @var \Drupal\Core\Annotation\Translation + */ + public $description; + } diff --git a/src/Display/DisplayInterface.php b/src/Display/DisplayInterface.php index ff6d49d..f7da4c3 100644 --- a/src/Display/DisplayInterface.php +++ b/src/Display/DisplayInterface.php @@ -16,18 +16,18 @@ interface DisplayInterface extends PluginInspectionInterface, DerivativeInspectionInterface { /** - * Returns the label for use on the administration pages. + * Returns the display label. * * @return string - * The administration label. + * A human-readable label for the display. */ public function label(); /** - * Returns the description for use on the administration pages. + * Returns the display description. * * @return string - * The description. + * A human-readable description for the display. */ public function getDescription(); diff --git a/src/Display/DisplayPluginBase.php b/src/Display/DisplayPluginBase.php index dd4118e..c411afe 100644 --- a/src/Display/DisplayPluginBase.php +++ b/src/Display/DisplayPluginBase.php @@ -4,7 +4,6 @@ use Drupal\Core\Plugin\PluginBase; use Drupal\search_api\Entity\Index; -use Drupal\search_api\Plugin\IndexPluginBase; /** * Defines a base class from which other display classes may extend. @@ -19,7 +18,8 @@ * @code * @SearchApiDisplay( * id = "my_display", - * label = @Translation("My display") + * label = @Translation("My display"), + * label = @Translation("My display"), * ) * @endcode * @@ -57,8 +57,8 @@ public function isRenderedInCurrentRequest() { * {@inheritdoc} */ public function getIndex() { - $definition = $this->getPluginDefinition(); - return Index::load($definition['index']); + $plugin_definition = $this->getPluginDefinition(); + return Index::load($plugin_definition['index']); } } diff --git a/src/Plugin/search_api/display/ViewsPageDisplay.php b/src/Plugin/search_api/display/ViewsPageDisplay.php index f3c7031..fc9bcc5 100644 --- a/src/Plugin/search_api/display/ViewsPageDisplay.php +++ b/src/Plugin/search_api/display/ViewsPageDisplay.php @@ -20,7 +20,7 @@ class ViewsPageDisplay extends DisplayPluginBase { * {@inheritdoc} */ public function getPath() { - return Url::fromUserInput('/' . $this->getViewsPagePath()); + return Url::fromUserInput($this->getViewsPagePath()); } /** @@ -28,16 +28,19 @@ public function getPath() { */ public function isRenderedInCurrentRequest() { $url = \Drupal::request()->getPathInfo(); - return $url == '/' . $this->getViewsPagePath(); + return $url == $this->getViewsPagePath(); } /** - * Returns the views page path for the current views page display. + * Returns the page path for this Views page display. + * + * @return string + * The display's base path, with a leading slash (/). */ protected function getViewsPagePath(){ $view = Views::getView($this->pluginDefinition['view_id']); $view->setDisplay($this->pluginDefinition['view_display']); - return $view->getDisplay()->getPath(); + return '/' . $view->getDisplay()->getPath(); } } diff --git a/src/Plugin/views/query/SearchApiQuery.php b/src/Plugin/views/query/SearchApiQuery.php index 08178e2..92af4b4 100644 --- a/src/Plugin/views/query/SearchApiQuery.php +++ b/src/Plugin/views/query/SearchApiQuery.php @@ -199,22 +199,15 @@ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$o $this->query->addTag('views_' . $view->id()); $this->query->setOption('search_api_view', $view); - switch($display->getPluginId()){ - case 'page': - // Views page is supported as a search api display. - // Load the search api display and attach it to the query. - $display_plugin_manager = \Drupal::service('plugin.manager.search_api.display'); - $search_api_display = $display_plugin_manager->createInstance('views_page:' . $display->view->id() . '__' . $display->view->current_display); - $this->query->setOption('search_api_display', $search_api_display); - break; - default: - // @todo figure out how to allow new displays for other views display - // types to be added, do we need a hook for this? - $this->query->setOption('search_api_display', NULL); - break; + // We only provide a display plugin for Views page displays. + // @todo figure out how to allow new displays for other views display + // types to be added. Do we need a hook for this? + if ($display->getPluginId() == 'page') { + // Load the Search API display and attach it to the query. + $display_plugin_manager = \Drupal::service('plugin.manager.search_api.display'); + $search_api_display = $display_plugin_manager->createInstance('views_page:' . $view->id() . '__' . $view->current_display); + $this->query->setOption('search_api_display', $search_api_display); } - - } catch (\Exception $e) { $this->abort($e->getMessage());