You are here

public function ViewsDeriver::getDerivativeDefinitions in Search API Autocomplete 8

Gets the definition of all derivatives of a base plugin.

Parameters

array $base_plugin_definition: The definition array of the base plugin.

Return value

array An array of full derivative definitions keyed on derivative id.

Overrides DeriverBase::getDerivativeDefinitions

See also

getDerivativeDefinition()

File

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

Class

ViewsDeriver
Derives a search plugin definition for every view.

Namespace

Drupal\search_api_autocomplete\Plugin\search_api_autocomplete\search

Code

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;
}