summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormpp2018-11-24 12:17:24 (GMT)
committerJoris Vercammen2018-11-24 12:17:24 (GMT)
commitc8414fd5376590ed13bf05f94424aca4d88c7d6f (patch)
tree20f9134e85c7ce68a1331d630522aaa8eb52545d
parent63a3765d91e7db582ab0f0b47ffdc843cea939cd (diff)
Issue #3006725 by mpp: Hide result for boolean fields when label is empty
-rw-r--r--src/Plugin/facets/processor/BooleanItemProcessor.php21
-rw-r--r--tests/src/Functional/ProcessorIntegrationTest.php23
2 files changed, 37 insertions, 7 deletions
diff --git a/src/Plugin/facets/processor/BooleanItemProcessor.php b/src/Plugin/facets/processor/BooleanItemProcessor.php
index 52f07a2..2f7ec6b 100644
--- a/src/Plugin/facets/processor/BooleanItemProcessor.php
+++ b/src/Plugin/facets/processor/BooleanItemProcessor.php
@@ -29,12 +29,19 @@ class BooleanItemProcessor extends ProcessorPluginBase implements BuildProcessor
$config = $this->getConfiguration();
/** @var \Drupal\facets\Result\Result $result */
- foreach ($results as $result) {
+ foreach ($results as $key => $result) {
+ $value = '';
if ($result->getRawValue() == 0) {
- $result->setDisplayValue($config['off_value']);
+ $value = $config['off_value'];
}
elseif ($result->getRawValue() == 1) {
- $result->setDisplayValue($config['on_value']);
+ $value = $config['on_value'];
+ }
+ if ($value == '') {
+ unset($results[$key]);
+ }
+ else {
+ $result->setDisplayValue($value);
}
}
@@ -51,9 +58,9 @@ class BooleanItemProcessor extends ProcessorPluginBase implements BuildProcessor
'#title' => $this->t('On value'),
'#type' => 'textfield',
'#default_value' => $config['on_value'],
- '#description' => $this->t('Use this label instead of <em>0</em> for the <em>On</em> or <em>True</em> value.'),
+ '#description' => $this->t('Use this label instead of <em>0</em> for the <em>On</em> or <em>True</em> value. Leave empty to hide this item.'),
'#states' => [
- 'required' => ['input[name="facet_settings[boolean_item][status]"' => ['checked' => TRUE]],
+ 'required' => ['input[name="facet_settings[boolean_item][settings][off_value]"' => ['empty' => TRUE]],
],
];
@@ -61,9 +68,9 @@ class BooleanItemProcessor extends ProcessorPluginBase implements BuildProcessor
'#title' => $this->t('Off value'),
'#type' => 'textfield',
'#default_value' => $config['off_value'],
- '#description' => $this->t('Use this label instead of <em>1</em> for the <em>Off</em> or <em>False</em> value.'),
+ '#description' => $this->t('Use this label instead of <em>1</em> for the <em>Off</em> or <em>False</em> value. Leave empty to hide this item.'),
'#states' => [
- 'required' => ['input[name="facet_settings[boolean_item][status]"' => ['checked' => TRUE]],
+ 'required' => ['input[name="facet_settings[boolean_item][settings][on_value]"' => ['empty' => TRUE]],
],
];
diff --git a/tests/src/Functional/ProcessorIntegrationTest.php b/tests/src/Functional/ProcessorIntegrationTest.php
index d2919ce..536edee 100644
--- a/tests/src/Functional/ProcessorIntegrationTest.php
+++ b/tests/src/Functional/ProcessorIntegrationTest.php
@@ -167,6 +167,14 @@ class ProcessorIntegrationTest extends FacetsTestBase {
'category' => 'item_category',
$field_name => TRUE,
])->save();
+ $entity_test_storage->create([
+ 'name' => 'quux quuux',
+ 'body' => 'test test',
+ 'type' => 'item',
+ 'keywords' => ['apple'],
+ 'category' => 'item_category',
+ $field_name => FALSE,
+ ])->save();
$this->indexItems($this->indexId);
@@ -180,6 +188,7 @@ class ProcessorIntegrationTest extends FacetsTestBase {
// Check values.
$this->drupalGet('search-api-test-fulltext');
$this->assertFacetLabel('1');
+ $this->assertFacetLabel('0');
$form = [
'facet_settings[boolean_item][status]' => TRUE,
@@ -192,6 +201,7 @@ class ProcessorIntegrationTest extends FacetsTestBase {
$this->drupalGet('search-api-test-fulltext');
$this->assertFacetLabel('Yes');
+ $this->assertFacetLabel('No');
$form = [
'facet_settings[boolean_item][status]' => TRUE,
@@ -201,6 +211,19 @@ class ProcessorIntegrationTest extends FacetsTestBase {
$this->drupalGet('search-api-test-fulltext');
$this->assertFacetLabel('Øn');
+ $this->assertEmpty($this->findFacetLink('1'));
+ $this->assertEmpty($this->findFacetLink('0'));
+
+ $form = [
+ 'facet_settings[boolean_item][status]' => TRUE,
+ 'facet_settings[boolean_item][settings][off_value]' => 'Øff',
+ ];
+ $this->drupalPostForm($this->editForm, $form, 'Save');
+
+ $this->drupalGet('search-api-test-fulltext');
+ $this->assertFacetLabel('Øff');
+ $this->assertEmpty($this->findFacetLink('1'));
+ $this->assertEmpty($this->findFacetLink('0'));
}
/**