You are here

public function Facet::getProcessorsByStage in Facets 8

Loads this facets processors for a specific stage.

Parameters

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

bool $only_enabled: (optional) If FALSE, also include disabled processors. Otherwise, only load enabled ones.

Return value

\Drupal\facets\Processor\ProcessorInterface[] An array of all enabled (or available, if if $only_enabled is FALSE) processors that support the given stage, ordered by the weight for that stage.

Overrides FacetInterface::getProcessorsByStage

File

src/Entity/Facet.php, line 865

Class

Facet
Defines the facet configuration entity.

Namespace

Drupal\facets\Entity

Code

public function getProcessorsByStage($stage, $only_enabled = TRUE) {
  $processors = $this
    ->getProcessors($only_enabled);
  $processor_settings = $this
    ->getProcessorConfigs();
  $processor_weights = [];

  // Get a list of all processors for given stage.
  foreach ($processors as $name => $processor) {
    if ($processor
      ->supportsStage($stage)) {
      if (!empty($processor_settings[$name]['weights'][$stage])) {
        $processor_weights[$name] = $processor_settings[$name]['weights'][$stage];
      }
      else {
        $processor_weights[$name] = $processor
          ->getDefaultWeight($stage);
      }
    }
  }

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