Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function build(FacetInterface $facet)
 {
     $this->facet = $facet;
     /** @var \Drupal\facets\Result\Result[] $results */
     $results = $facet->getResults();
     $items = [];
     $configuration = $facet->getWidgetConfigs();
     $this->showNumbers = empty($configuration['show_numbers']) ? FALSE : (bool) $configuration['show_numbers'];
     $this->defaultOptionLabel = isset($configuration['default_option_label']) ? $configuration['default_option_label'] : '';
     foreach ($results as $result) {
         if (is_null($result->getUrl())) {
             $text = $this->extractText($result);
             $items[] = ['#markup' => $text];
         } else {
             $items[] = $this->buildListItems($result);
         }
     }
     $build = ['#theme' => 'item_list', '#items' => $items, '#attributes' => ['class' => ['js-facets-dropdown-links'], 'data-facet-default-option-label' => $this->defaultOptionLabel], '#cache' => ['contexts' => ['url.path', 'url.query_args']]];
     $build['#attached']['library'][] = 'facets/drupal.facets.dropdown-widget';
     return $build;
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public function build(FacetInterface $facet)
 {
     /** @var \Drupal\facets\Result\Result[] $results */
     $results = $facet->getResults();
     $items = [];
     $configuration = $facet->getWidgetConfigs();
     $this->showNumbers = empty($configuration['show_numbers']) ? FALSE : (bool) $configuration['show_numbers'];
     foreach ($results as $result) {
         if (is_null($result->getUrl())) {
             $text = $this->extractText($result);
             $items[] = ['#markup' => $text];
         } else {
             $items[] = $this->buildListItems($result);
         }
     }
     $build = ['#theme' => 'item_list', '#items' => $items, '#attributes' => ['data-drupal-facet-id' => $facet->id()], '#cache' => ['contexts' => ['url.path', 'url.query_args']]];
     if (!empty($configuration['soft_limit'])) {
         $build['#attached']['library'][] = 'facets/soft-limit';
         $build['#attached']['drupalSettings']['facets']['softLimit'][$facet->id()] = (int) $configuration['soft_limit'];
     }
     return $build;
 }