getPluginCollection()->get($this->plugin); } /** * Encapsulates the creation of the search page's LazyPluginCollection. * * @return \Drupal\Component\Plugin\LazyPluginCollection * The search page's plugin collection. */ protected function getPluginCollection() { if (!$this->pluginCollection) { $this->pluginCollection = new SearchPluginCollection($this->searchPluginManager(), $this->plugin, $this->configuration, $this->id()); } return $this->pluginCollection; } /** * {@inheritdoc} */ public function getPluginCollections() { return ['configuration' => $this->getPluginCollection()]; } /** * {@inheritdoc} */ public function setPlugin($plugin_id) { $this->plugin = $plugin_id; $this->getPluginCollection()->addInstanceID($plugin_id); } /** * {@inheritdoc} */ public function isIndexable() { return $this->status() && $this->getPlugin() instanceof SearchIndexingInterface; } /** * {@inheritdoc} */ public function isDefaultSearch() { return $this->searchPageRepository()->getDefaultSearchPage() == $this->id(); } /** * {@inheritdoc} */ public function getPath() { return $this->path; } /** * {@inheritdoc} */ public function getWeight() { return $this->weight; } /** * {@inheritdoc} */ public function postCreate(EntityStorageInterface $storage) { parent::postCreate($storage); // @todo Use self::applyDefaultValue() once // https://www.drupal.org/node/2004756 is in. if (!isset($this->weight)) { $this->weight = $this->isDefaultSearch() ? -10 : 0; } } /** * {@inheritdoc} */ public function postSave(EntityStorageInterface $storage, $update = TRUE) { parent::postSave($storage, $update); $this->routeBuilder()->setRebuildNeeded(); } /** * {@inheritdoc} */ public static function postDelete(EntityStorageInterface $storage, array $entities) { parent::postDelete($storage, $entities); $search_page_repository = \Drupal::service('search.search_page_repository'); if (!$search_page_repository->isSearchActive()) { $search_page_repository->clearDefaultSearchPage(); } } /** * {@inheritdoc} */ public static function sort(ConfigEntityInterface $a, ConfigEntityInterface $b) { /** @var $a \Drupal\search\SearchPageInterface */ /** @var $b \Drupal\search\SearchPageInterface */ $a_status = (int) $a->status(); $b_status = (int) $b->status(); if ($a_status != $b_status) { return ($a_status > $b_status) ? -1 : 1; } return parent::sort($a, $b); } /** * Wraps the route builder. * * @return \Drupal\Core\Routing\RouteBuilderInterface * An object for state storage. */ protected function routeBuilder() { return \Drupal::service('router.builder'); } /** * Wraps the config factory. * * @return \Drupal\Core\Config\ConfigFactoryInterface * A config factory object. */ protected function configFactory() { return \Drupal::service('config.factory'); } /** * Wraps the search page repository. * * @return \Drupal\search\SearchPageRepositoryInterface * A search page repository object. */ protected function searchPageRepository() { return \Drupal::service('search.search_page_repository'); } /** * Wraps the search plugin manager. * * @return \Drupal\Component\Plugin\PluginManagerInterface * A search plugin manager object. */ protected function searchPluginManager() { return \Drupal::service('plugin.manager.search'); } }