You are here

protected function GlossaryAZWidget::prepareLink 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::prepareLink()
  2. 8.2 src/Plugin/facets/widget/GlossaryAZWidget.php \Drupal\search_api_glossary\Plugin\facets\widget\GlossaryAZWidget::prepareLink()
  3. 8.3 src/Plugin/facets/widget/GlossaryAZWidget.php \Drupal\search_api_glossary\Plugin\facets\widget\GlossaryAZWidget::prepareLink()

Returns the text or link for an item.

Parameters

\Drupal\facets\Result\ResultInterface $result: A result item.

Return value

array The item, as a renderable array.

Overrides WidgetPluginBase::prepareLink

1 call to GlossaryAZWidget::prepareLink()
GlossaryAZWidget::buildListItems in src/Plugin/facets/widget/GlossaryAZWidget.php
Builds a renderable array of result items.

File

src/Plugin/facets/widget/GlossaryAZWidget.php, line 106

Class

GlossaryAZWidget
The GlossaryAZ widget.

Namespace

Drupal\search_api_glossary\Plugin\facets\widget

Code

protected function prepareLink(ResultInterface $result) {
  $configuration = $this
    ->getConfiguration();
  $show_count = empty($configuration['show_count']) ? FALSE : (bool) $configuration['show_count'];
  $text = $result
    ->getDisplayValue();
  if ($show_count) {
    $text .= ' (' . $result
      ->getCount() . ')';
  }
  if (is_null($result
    ->getUrl()) || $result
    ->getCount() == 0) {
    $link = [
      '#markup' => $text,
    ];
  }
  else {
    $link = new Link($text, $result
      ->getUrl());
    $link = $link
      ->toRenderable();
  }
  return $link;
}