You are here

public function GlossaryAZWidget::build in Search API AZ Glossary 8

Same name and namespace in other branches
  1. 8.4 src/Plugin/facets/widget/GlossaryAZWidget.php \Drupal\search_api_glossary\Plugin\facets\widget\GlossaryAZWidget::build()
  2. 8.2 src/Plugin/facets/widget/GlossaryAZWidget.php \Drupal\search_api_glossary\Plugin\facets\widget\GlossaryAZWidget::build()
  3. 8.3 src/Plugin/facets/widget/GlossaryAZWidget.php \Drupal\search_api_glossary\Plugin\facets\widget\GlossaryAZWidget::build()

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/GlossaryAZWidget.php, line 26

Class

GlossaryAZWidget
The GlossaryAZ widget.

Namespace

Drupal\search_api_glossary\Plugin\facets\widget

Code

public function build(FacetInterface $facet) {

  /** @var \Drupal\facets\Result\Result[] $results */
  $results = $facet
    ->getResults();
  $items = [];
  $configuration = $facet
    ->getWidget()['config'];
  $enable_default_theme = empty($configuration['enable_default_theme']) ? FALSE : (bool) $configuration['enable_default_theme'];
  foreach ($results as $result) {
    $items[] = $this
      ->buildListItems($result);
  }
  $build = [
    '#theme' => 'item_list',
    '#items' => $items,
    '#cache' => [
      'contexts' => [
        'url.path',
        'url.query_args',
      ],
    ],
  ];
  if ($enable_default_theme) {
    $build['#attached'] = array(
      'library' => array(
        'search_api_glossary/drupal.search_api_glossary.facet_css',
      ),
    );
  }
  return $build;
}