You are here

class ViewsDeriver in Search API Autocomplete 8

Derives a search plugin definition for every view.

Hierarchy

Expanded class hierarchy of ViewsDeriver

See also

\Drupal\search_api_autocomplete\Plugin\search_api_autocomplete\search\Views

File

src/Plugin/search_api_autocomplete/search/ViewsDeriver.php, line 15

Namespace

Drupal\search_api_autocomplete\Plugin\search_api_autocomplete\search
View source
class ViewsDeriver extends SearchPluginDeriverBase {

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {
    if (!isset($this->derivatives)) {
      $this->derivatives = [];
      try {

        /** @var \Drupal\Core\Entity\EntityStorageInterface $views_storage */
        $views_storage = $this
          ->getEntityTypeManager()
          ->getStorage('view');
      } catch (PluginException $e) {
        return $this->derivatives;
      }

      /** @var \Drupal\views\ViewEntityInterface $view */
      foreach ($views_storage
        ->loadMultiple() as $view) {
        $index = SearchApiQuery::getIndexFromTable($view
          ->get('base_table'));
        if (!$index instanceof IndexInterface) {
          continue;
        }
        $this->derivatives[$view
          ->id()] = [
          'label' => $view
            ->label(),
          'index' => $index
            ->id(),
        ] + $base_plugin_definition;
      }
    }
    return $this->derivatives;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DeriverBase::getDerivativeDefinition public function Gets the definition of a derivative plugin. Overrides DeriverInterface::getDerivativeDefinition
SearchPluginDeriverBase::$derivatives protected property List of derivative definitions. Overrides DeriverBase::$derivatives
SearchPluginDeriverBase::$entityTypeManager protected property The entity manager.
SearchPluginDeriverBase::$instances protected static property Existing instances of this class.
SearchPluginDeriverBase::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
SearchPluginDeriverBase::getEntityTypeManager public function Retrieves the entity manager.
SearchPluginDeriverBase::resetStaticDerivativeCaches public static function Resets the statically cached derivatives for all instances of this class.
SearchPluginDeriverBase::setEntityTypeManager public function Sets the entity manager.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
ViewsDeriver::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions