You are here

public function ArrayWidget::build in Facets 8

Builds the facet widget for rendering.

Parameters

\Drupal\facets\FacetInterface $facet: The facet we need to build.

Return value

array A renderable array.

Overrides WidgetPluginBase::build

File

src/Plugin/facets/widget/ArrayWidget.php, line 23

Class

ArrayWidget
A simple widget class that returns a simple array of the facet results.

Namespace

Drupal\facets\Plugin\facets\widget

Code

public function build(FacetInterface $facet) {

  /** @var \Drupal\facets\Result\Result[] $results */
  $results = $facet
    ->getResults();
  $items = [];
  $configuration = $facet
    ->getWidget();
  $this->showNumbers = empty($configuration['show_numbers']) ? FALSE : (bool) $configuration['show_numbers'];
  foreach ($results as $result) {
    if (is_null($result
      ->getUrl())) {
      $text = $this
        ->generateValues($result);
      $items[$facet
        ->getFieldIdentifier()][] = $text;
    }
    else {
      $items[$facet
        ->getFieldIdentifier()][] = $this
        ->buildListItems($facet, $result);
    }
  }
  return $items;
}