Exemple #1
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;
 }