You are here

public function PageDeriver::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/PageDeriver.php, line 18

Class

PageDeriver
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 {
      $page_storage = $this
        ->getEntityTypeManager()
        ->getStorage('search_api_page');
      $index_storage = $this
        ->getEntityTypeManager()
        ->getStorage('search_api_index');
    } catch (PluginException $e) {
      return $this->derivatives;
    }

    /** @var \Drupal\search_api_page\SearchApiPageInterface $page */
    foreach ($page_storage
      ->loadMultiple() as $page) {
      $index = $index_storage
        ->load($page
        ->getIndex());
      $this->derivatives[$page
        ->id()] = [
        'label' => $page
          ->label(),
        'index' => $index
          ->id(),
      ] + $base_plugin_definition;
    }
  }
  return $this->derivatives;
}