diff --git a/src/FacetManager/DefaultFacetManager.php b/src/FacetManager/DefaultFacetManager.php index 0718e96..8523a51 100644 --- a/src/FacetManager/DefaultFacetManager.php +++ b/src/FacetManager/DefaultFacetManager.php @@ -320,9 +320,13 @@ class DefaultFacetManager { $facet_source_plugin->fillFacetsWithResults($this->facets); } - /** - * Makes sure facets are processed and returns the updated facet entity. + * Returns one of the processed facets. + * + * Returns one of the processed facets, this is a facet with filled results. + * Keep in mind that if you want to have the facet's build processor executed, + * there needs to be an extra call to the FacetManager::build with the facet + * returned here as argument. * * @param string $facet_id * The id of the facet. diff --git a/src/Plugin/Condition/OtherFacet.php b/src/Plugin/Condition/OtherFacet.php index 38722db..b706466 100644 --- a/src/Plugin/Condition/OtherFacet.php +++ b/src/Plugin/Condition/OtherFacet.php @@ -20,6 +20,10 @@ use Symfony\Component\DependencyInjection\ContainerInterface; /** * Provides an 'other facet' condition. * + * This adds a condition plugin to make sure that facets can depend on other + * facet's or their values. The facet value is a freeform textfield and works on + * both raw and display values of the results. + * * @Condition( * id = "other_facet", * label = @Translation("Other facet"), @@ -28,7 +32,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; class OtherFacet extends ConditionPluginBase implements ContainerFactoryPluginInterface { /** - * The entity storage. + * The facet entity storage. * * @var \Drupal\Core\Entity\EntityStorageInterface */ @@ -105,6 +109,8 @@ class OtherFacet extends ConditionPluginBase implements ContainerFactoryPluginIn public function buildConfigurationForm(array $form, FormStateInterface $form_state) { $options = []; + // Loop over all defined blocks and filter them by provider, this builds an + // array of blocks that are provided by the facets module. foreach ($this->blockManager->getDefinitions() as $definition) { if ($definition['provider'] == 'facets') { $options[$definition['id']] = $definition['label']; @@ -140,8 +146,10 @@ class OtherFacet extends ConditionPluginBase implements ContainerFactoryPluginIn * {@inheritdoc} */ public function summary() { - $facet = reset($this->configuration['facets']); - return $this->t('The facet is @facet also rendered on the same page.', ['@facet' => $facet]); + return $this->t( + 'The facet is @facet also rendered on the same page.', + ['@facet' => $this->configuration['facets']] + ); } /** @@ -161,11 +169,15 @@ class OtherFacet extends ConditionPluginBase implements ContainerFactoryPluginIn $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. + // 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]; diff --git a/src/Tests/IntegrationTest.php b/src/Tests/IntegrationTest.php index e939b41..147e294 100644 --- a/src/Tests/IntegrationTest.php +++ b/src/Tests/IntegrationTest.php @@ -35,6 +35,9 @@ class IntegrationTest extends FacetWebTestBase { $this->setUpExampleStructure(); $this->insertExampleContent(); $this->assertEqual($this->indexItems($this->indexId), 5, '5 items were indexed.'); + + // Make absolutely sure the ::$blocks variable doesn't pass information + // along between tests. $this->blocks = NULL; } diff --git a/tests/src/Unit/Plugin/Condition/OtherFacetTest.php b/tests/src/Unit/Plugin/Condition/OtherFacetTest.php index fce0789..dc0860a 100644 --- a/tests/src/Unit/Plugin/Condition/OtherFacetTest.php +++ b/tests/src/Unit/Plugin/Condition/OtherFacetTest.php @@ -13,7 +13,7 @@ use Drupal\facets\Result\Result; use Drupal\Tests\UnitTestCase; /** - * Unit test for condition. + * Unit test for the 'other facet' condition plugin. * * @group facets */ @@ -38,7 +38,7 @@ class OtherFacetTest extends UnitTestCase { } /** - * Displayed facet. + * Tests the return value of the plugin for a displayed facet. */ public function testDisplayedFacet() { $block = $this->getMockBuilder('\Drupal\facets\Plugin\Block\FacetBlock') @@ -65,7 +65,7 @@ class OtherFacetTest extends UnitTestCase { } /** - * Hidden facet. + * Tests the return value of the plugin for a hidden facet. */ public function testHiddenFacet() { $block = $this->getMockBuilder('\Drupal\facets\Plugin\Block\FacetBlock') @@ -92,7 +92,7 @@ class OtherFacetTest extends UnitTestCase { } /** - * Active facet value. + * Tests the return value of the plugin for an active facet value. */ public function testActiveFacetValue() { $facet = new Facet([], 'facets_facet'); @@ -140,7 +140,7 @@ class OtherFacetTest extends UnitTestCase { } /** - * Active facet value. + * Tests the return value of the plugin for an inactive facet value. */ public function testInactiveFacetValue() { $facet = new Facet([], 'facets_facet');