You are here

public function Index::getProcessorsByStage in Search API 8

Loads this index's processors for a specific stage.

Parameters

string $stage: The stage for which to return the processors. One of the \Drupal\search_api\Processor\ProcessorInterface::STAGE_* constants.

array[] $overrides: (optional) Overrides to apply to the index's processors, keyed by processor IDs with their respective overridden settings as values.

Return value

\Drupal\search_api\Processor\ProcessorInterface[] An array of all enabled processors that support the given stage, ordered by the weight for that stage.

Overrides IndexInterface::getProcessorsByStage

6 calls to Index::getProcessorsByStage()
Index::alterIndexedItems in src/Entity/Index.php
Alter the items to be indexed.
Index::getPropertyDefinitions in src/Entity/Index.php
Retrieves the properties of one of this index's datasources.
Index::postprocessSearchResults in src/Entity/Index.php
Postprocesses search results before they are displayed.
Index::preprocessIndexItems in src/Entity/Index.php
Preprocesses data items for indexing.
Index::preprocessSearchQuery in src/Entity/Index.php
Preprocesses a search query.

... See full list

File

src/Entity/Index.php, line 548

Class

Index
Defines the search index configuration entity.

Namespace

Drupal\search_api\Entity

Code

public function getProcessorsByStage($stage, array $overrides = []) {

  // Get a list of all processors which support this stage, along with their
  // weights.
  $processors = $this
    ->getProcessors();
  $processor_weights = [];
  foreach ($processors as $name => $processor) {
    if ($processor
      ->supportsStage($stage)) {
      $processor_weights[$name] = $processor
        ->getWeight($stage);
    }
  }

  // Apply any overrides that were passed by the caller.
  $plugin_helper = \Drupal::getContainer()
    ->get('search_api.plugin_helper');
  foreach ($overrides as $name => $config) {
    $processor = $plugin_helper
      ->createProcessorPlugin($this, $name, $config);
    if ($processor
      ->supportsStage($stage)) {
      $processors[$name] = $processor;
      $processor_weights[$name] = $processor
        ->getWeight($stage);
    }
    else {

      // In rare cases, the override might change whether or not the processor
      // supports the given stage. So, to make sure, unset the weight in case
      // it was set before.
      unset($processor_weights[$name]);
    }
  }

  // Sort requested processors by weight.
  asort($processor_weights);
  $return_processors = [];
  foreach ($processor_weights as $name => $weight) {
    $return_processors[$name] = $processors[$name];
  }
  return $return_processors;
}