You are here

protected function GlossaryAZWidget::prepareLink in Search API AZ Glossary 8.4

Same name and namespace in other branches
  1. 8 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 99

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();

  // TODO revise this logic based on progress with
  // All items count is not correct when narrowing the results.
  // https://www.drupal.org/project/facets/issues/2692027
  // see https://git.drupalcode.org/project/facets/commit/21343a6
  if ($show_count && $result
    ->getRawValue() != 'All') {
    $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;
}