You are here

public function BooleanItemProcessor::build in Facets 8

Runs before the renderable array is created.

Parameters

\Drupal\facets\FacetInterface $facet: The facet being changed.

\Drupal\facets\Result\ResultInterface[] $results: The results being changed.

Return value

\Drupal\facets\Result\ResultInterface[] The changed results.

Overrides BuildProcessorInterface::build

File

src/Plugin/facets/processor/BooleanItemProcessor.php, line 28

Class

BooleanItemProcessor
Provides a processor for boolean labels.

Namespace

Drupal\facets\Plugin\facets\processor

Code

public function build(FacetInterface $facet, array $results) {
  $config = $this
    ->getConfiguration();

  /** @var \Drupal\facets\Result\Result $result */
  foreach ($results as $key => $result) {
    $value = '';
    if ($result
      ->getRawValue() == 0) {
      $value = $config['off_value'];
    }
    elseif ($result
      ->getRawValue() == 1) {
      $value = $config['on_value'];
    }
    if ($value == '') {
      unset($results[$key]);
    }
    else {
      $result
        ->setDisplayValue($value);
    }
  }
  return $results;
}