You are here

protected function DefaultFacetManager::initFacets in Facets 8

Initializes enabled facets.

In this method all pre-query processors get called and their contents are executed.

Throws

\Drupal\facets\Exception\InvalidProcessorException Thrown if one of the pre query processors is invalid.

2 calls to DefaultFacetManager::initFacets()
DefaultFacetManager::build in src/FacetManager/DefaultFacetManager.php
Builds a facet and returns it as a renderable array.
DefaultFacetManager::getFacetsByFacetSourceId in src/FacetManager/DefaultFacetManager.php
Returns currently rendered facets filtered by facetsource ID.

File

src/FacetManager/DefaultFacetManager.php, line 211

Class

DefaultFacetManager
The facet manager.

Namespace

Drupal\facets\FacetManager

Code

protected function initFacets() {
  if (count($this->facets) > 0) {
    return;
  }
  $this->facets = $this
    ->getEnabledFacets();
  foreach ($this->facets as $facet) {
    foreach ($facet
      ->getProcessorsByStage(ProcessorInterface::STAGE_PRE_QUERY) as $processor) {

      /** @var \Drupal\facets\Processor\PreQueryProcessorInterface $pre_query_processor */
      $pre_query_processor = $facet
        ->getProcessors()[$processor
        ->getPluginDefinition()['id']];
      if (!$pre_query_processor instanceof PreQueryProcessorInterface) {
        throw new InvalidProcessorException("The processor {$processor->getPluginDefinition()['id']} has a pre_query definition but doesn't implement the required PreQueryProcessorInterface interface");
      }
      $pre_query_processor
        ->preQuery($facet);
    }
  }
}