Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function build()
 {
     // The id saved in the configuration is in the format of
     // base_plugin:facet_id. We're splitting that to get to the facet id.
     $facet_mapping = $this->configuration['id'];
     $facet_id = explode(PluginBase::DERIVATIVE_SEPARATOR, $facet_mapping)[1];
     /** @var \Drupal\facets\FacetInterface $facet */
     $facet = $this->facetStorage->load($facet_id);
     // Let the facet_manager build the facets.
     $build = $this->facetManager->build($facet);
     // Add contextual links only when we have results.
     if (!empty($build)) {
         $build['#contextual_links']['facets_facet'] = ['route_parameters' => ['facets_facet' => $facet->id()]];
     }
     return $build;
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public function evaluate()
 {
     $allowed_facet_value = $this->configuration['facet_value'];
     $allowed_facets = $this->configuration['facets'];
     // Return as early as possible when there are no settings for allowed
     // facets.
     if (empty($allowed_facets)) {
         return TRUE;
     }
     /** @var \Drupal\facets\Plugin\Block\FacetBlock $block_plugin */
     $block_plugin = $this->blockManager->createInstance($allowed_facets);
     // Allowed facet value is not set, so we only have to check if the block is
     // shown here by running the access method on the block plugin with the
     // currently logged in user.
     if (empty($allowed_facet_value)) {
         return $block_plugin->access($this->currentUser);
     }
     // The block plugin id is saved in the schema: BasePluginID:FacetID. This
     // means we can explode the ID on ':' and the facet id is in the last part
     // of that result.
     $block_plugin_id = $block_plugin->getPluginId();
     $facet_id = explode(PluginBase::DERIVATIVE_SEPARATOR, $block_plugin_id)[1];
     /** @var \Drupal\facets\FacetInterface $facet */
     $facet = $this->facetStorage->load($facet_id);
     $facet = $this->facetManager->returnProcessedFacet($facet);
     foreach ($facet->getResults() as $result) {
         $is_value = $result->getRawValue() == $allowed_facet_value || $result->getDisplayValue() == $allowed_facet_value;
         if ($is_value && $result->isActive()) {
             return TRUE;
         }
     }
     return FALSE;
 }