public function setUp() { $this->account = $this->prophesize(AccountInterface::class); $this->contextHandler = $this->prophesize(ContextHandlerInterface::class); $this->uuidGenerator = $this->prophesize(UuidInterface::class); $this->token = $this->prophesize(Token::class); $this->blockManager = $this->prophesize(BlockManager::class); $this->conditionManager = $this->prophesize(ConditionManager::class); $this->builderManager = $this->prophesize(DisplayBuilderManagerInterface::class); $this->layoutManager = $this->prophesize(LayoutPluginManagerInterface::class); $this->layout = $this->prophesize(LayoutInterface::class); $this->layoutManager->createInstance(Argument::type('string'), Argument::type('array'))->willReturn($this->layout->reveal()); $this->variant = new PanelsDisplayVariant([], '', [], $this->contextHandler->reveal(), $this->account->reveal(), $this->uuidGenerator->reveal(), $this->token->reveal(), $this->blockManager->reveal(), $this->conditionManager->reveal(), $this->builderManager->reveal(), $this->layoutManager->reveal()); }
/** * {@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; }