You are here

public function JsonApiFacetsDeriver::getDerivativeDefinitions in JSON:API Search API 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 DeriverInterface::getDerivativeDefinitions

See also

getDerivativeDefinition()

File

modules/jsonapi_search_api_facets/src/Plugin/facets/facet_source/JsonApiFacetsDeriver.php, line 16

Class

JsonApiFacetsDeriver
Derives a facet source plugin definition for every index.

Namespace

Drupal\jsonapi_search_api_facets\Plugin\facets\facet_source

Code

public function getDerivativeDefinitions($base_plugin_definition) {
  $derivatives = [];
  foreach ($this->entityTypeManager
    ->getStorage('search_api_index')
    ->getQuery()
    ->execute() as $index) {

    // Only derive for an index that supports facets.
    if ($this->entityTypeManager
      ->getStorage('search_api_index')
      ->load($index)
      ->getServerInstance()
      ->supportsFeature('search_api_facets')) {
      $derivatives[$index] = [
        'id' => $base_plugin_definition['id'] . PluginBase::DERIVATIVE_SEPARATOR . $index,
        'display_id' => strtr('jsonapi_search_api_facets_!index', [
          '!index' => $index,
        ]),
        'label' => $this
          ->t('JSON:API Search API Facets: @index', [
          '@index' => $index,
        ]),
        'index' => $index,
      ] + $base_plugin_definition;
    }
  }
  return $derivatives;
}