You are here

public function SearchApiSortsBlockDeriver::getDerivativeDefinitions in Search API sorts 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()

1 call to SearchApiSortsBlockDeriver::getDerivativeDefinitions()
SearchApiSortsBlockDeriver::getDerivativeDefinition in src/Plugin/Block/SearchApiSortsBlockDeriver.php
Gets the definition of a derivative plugin.

File

src/Plugin/Block/SearchApiSortsBlockDeriver.php, line 51

Class

SearchApiSortsBlockDeriver
This deriver creates a block for every index that has been created.

Namespace

Drupal\search_api_sorts\Plugin\Block

Code

public function getDerivativeDefinitions($base_plugin_definition) {
  $base_plugin_id = $base_plugin_definition['id'];
  if (!isset($this->derivatives[$base_plugin_id])) {
    $plugin_derivatives = [];

    /** @var \Drupal\search_api\Display\DisplayPluginManagerInterface $sapi_display_manager */
    $sapi_display_manager = \Drupal::service('plugin.manager.search_api.display');
    foreach ($sapi_display_manager
      ->getInstances() as $display) {
      $machine_name = $display
        ->getPluginId();
      $plugin_derivatives[$machine_name] = [
        'search_api_index' => $display
          ->getIndex(),
        'search_api_display' => $display,
        'id' => $base_plugin_id . PluginBase::DERIVATIVE_SEPARATOR . $machine_name,
        'admin_label' => $this
          ->t('Sort by (@index)', [
          '@index' => strip_tags($display
            ->label()),
        ]),
      ] + $base_plugin_definition;
    }
    $this->derivatives[$base_plugin_id] = $plugin_derivatives;
  }
  return $this->derivatives[$base_plugin_id];
}