Loading modules/facets_summary/config/schema/facets_summary.processor.schema.yml +3 −0 Original line number Diff line number Diff line Loading @@ -22,3 +22,6 @@ plugin.plugin_configuration.facets_summary_processor.reset_facets: link_text: type: label label: 'The text to show for the reset link.' position: type: string label: 'Position of the reset link.' modules/facets_summary/facets_summary.install +24 −0 Original line number Diff line number Diff line Loading @@ -5,7 +5,10 @@ * Update hooks for the facets summary module. */ use Drupal\Core\Config\Entity\ConfigEntityUpdater; use Drupal\facets_summary\Entity\FacetsSummary; use Drupal\facets_summary\FacetsSummaryInterface; use Drupal\facets_summary\Plugin\facets_summary\processor\ResetFacetsProcessor; /** * Convert summaries on Search Api facet sources to use the display plugin. Loading @@ -26,3 +29,24 @@ function facets_summary_update_8001() { } } } /** * Set reset link position default value for all existing Facet summary. */ function facets_summary_update_8002(&$sandbox = NULL) { \Drupal::classResolver(ConfigEntityUpdater::class)->update($sandbox, 'facets_summary', function ($facets_summary) { $update = FALSE; if ($facets_summary instanceof FacetsSummaryInterface) { $processor_settings = $facets_summary->getProcessorConfigs(); if (isset($processor_settings['reset_facets'])) { $processor_settings['reset_facets']['settings']['position'] = ResetFacetsProcessor::POSITION_BEFORE; $facets_summary->addProcessor($processor_settings['reset_facets']); $update = TRUE; } } return $update; }); } modules/facets_summary/src/Plugin/facets_summary/processor/ResetFacetsProcessor.php +45 −2 Original line number Diff line number Diff line Loading @@ -23,6 +23,21 @@ use Drupal\facets_summary\Processor\ProcessorPluginBase; */ class ResetFacetsProcessor extends ProcessorPluginBase implements BuildProcessorInterface { /** * Indicates that reset link should be positioned before facet links. */ const POSITION_BEFORE = 'before'; /** * Indicates that reset link should be positioned after facet links. */ const POSITION_AFTER = 'after'; /** * Indicates that reset link should replace facet links. */ const POSITION_REPLACE = 'replace'; /** * {@inheritdoc} */ Loading Loading @@ -93,7 +108,20 @@ class ResetFacetsProcessor extends ProcessorPluginBase implements BuildProcessor 'facet-summary-item--clear', ], ]; // Place link at necessary position. if ($configuration['settings']['position'] == static::POSITION_BEFORE) { array_unshift($build['#items'], $item); } elseif ($configuration['settings']['position'] == static::POSITION_AFTER) { $build['#items'][] = $item; } else { $build['#items'] = [ $item, ]; } return $build; } Loading @@ -110,6 +138,18 @@ class ResetFacetsProcessor extends ProcessorPluginBase implements BuildProcessor '#default_value' => $config['link_text'], ]; $build['position'] = [ '#type' => 'select', '#options' => [ static::POSITION_BEFORE => $this->t('Show reset link before facets links'), static::POSITION_AFTER => $this->t('Show reset link after facets links'), static::POSITION_REPLACE => $this->t('Show only reset link'), ], '#title' => $this->t('Position'), '#description' => $this->t('Set position of the link to display it before, after or instead of facets links.'), '#default_value' => $config['position'], ]; return $build; } Loading @@ -117,7 +157,10 @@ class ResetFacetsProcessor extends ProcessorPluginBase implements BuildProcessor * {@inheritdoc} */ public function defaultConfiguration() { return ['link_text' => '']; return [ 'link_text' => '', 'position' => static::POSITION_BEFORE, ]; } } modules/facets_summary/tests/src/Functional/IntegrationTest.php +13 −2 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ namespace Drupal\Tests\facets_summary\Functional; use Drupal\Tests\facets\Functional\FacetsTestBase; use Drupal\facets_summary\Entity\FacetsSummary; use Drupal\facets_summary\Plugin\facets_summary\processor\ResetFacetsProcessor; use Drupal\views\Views; /** Loading Loading @@ -395,9 +396,14 @@ class IntegrationTest extends FacetsTestBase { $this->assertSession()->pageTextContains($this->t('Facets Summary Owl has been updated.')); $this->assertSession()->fieldExists('facets_summary_settings[reset_facets][settings][link_text]'); $this->submitForm(['facets_summary_settings[reset_facets][settings][link_text]' => 'Reset facets'], 'Save'); $this->assertSession()->fieldExists('facets_summary_settings[reset_facets][settings][position]'); $this->submitForm([ 'facets_summary_settings[reset_facets][settings][link_text]' => 'Reset facets', 'facets_summary_settings[reset_facets][settings][position]' => ResetFacetsProcessor::POSITION_BEFORE, ], 'Save'); $this->assertSession()->pageTextContains($this->t('Facets Summary Owl has been updated.')); $this->assertSession()->fieldValueEquals('facets_summary_settings[reset_facets][settings][link_text]', 'Reset facets'); $this->assertSession()->fieldValueEquals('facets_summary_settings[reset_facets][settings][position]', ResetFacetsProcessor::POSITION_BEFORE); } /** Loading Loading @@ -483,7 +489,10 @@ class IntegrationTest extends FacetsTestBase { 'reset_facets' => [ 'processor_id' => 'reset_facets', 'weights' => ['build' => -10], 'settings' => ['link_text' => 'Reset facets'], 'settings' => [ 'link_text' => 'Reset facets', 'position' => ResetFacetsProcessor::POSITION_BEFORE, ], ], ], ])->save(); Loading Loading @@ -564,6 +573,7 @@ class IntegrationTest extends FacetsTestBase { 'facets[keywords][weight]' => 1, 'facets_summary_settings[reset_facets][status]' => 1, 'facets_summary_settings[reset_facets][settings][link_text]' => 'Reset', 'facets_summary_settings[reset_facets][settings][position]' => ResetFacetsProcessor::POSITION_BEFORE, ]; $this->drupalGet('admin/config/search/facets/facet-summary/kepler/edit'); $this->submitForm($summaries, 'Save'); Loading Loading @@ -612,6 +622,7 @@ class IntegrationTest extends FacetsTestBase { 'facets[orval][weight]' => 0, 'facets_summary_settings[reset_facets][status]' => 1, 'facets_summary_settings[reset_facets][settings][link_text]' => 'Reset', 'facets_summary_settings[reset_facets][settings][position]' => ResetFacetsProcessor::POSITION_BEFORE, ]; $this->drupalGet('admin/config/search/facets/facet-summary/trappist/edit'); $this->submitForm($summaries, 'Save'); Loading modules/facets_summary/tests/src/Unit/Plugin/Processor/ResetFacetsProcessorTest.php +10 −2 Original line number Diff line number Diff line Loading @@ -34,7 +34,12 @@ class ResetFacetsProcessorTest extends UnitTestCase { $container->set('string_translation', $string_translation->reveal()); \Drupal::setContainer($container); $this->processor = new ResetFacetsProcessor(['settings' => ['link_text' => 'Text']], 'reset_facets', []); $this->processor = new ResetFacetsProcessor([ 'settings' => [ 'link_text' => 'Text', 'position' => ResetFacetsProcessor::POSITION_BEFORE, ], ], 'reset_facets', []); } /** Loading Loading @@ -66,7 +71,10 @@ class ResetFacetsProcessorTest extends UnitTestCase { $config = [ 'processor_id' => 'reset_facets', 'weights' => [], 'settings' => ['link_text' => 'Text'], 'settings' => [ 'link_text' => 'Text', 'position' => ResetFacetsProcessor::POSITION_BEFORE, ], ]; $summary->addProcessor($config); Loading src/Plugin/facets/processor/HierarchyProcessor.php +1 −1 File changed.Contains only whitespace changes. Show changes Loading
modules/facets_summary/config/schema/facets_summary.processor.schema.yml +3 −0 Original line number Diff line number Diff line Loading @@ -22,3 +22,6 @@ plugin.plugin_configuration.facets_summary_processor.reset_facets: link_text: type: label label: 'The text to show for the reset link.' position: type: string label: 'Position of the reset link.'
modules/facets_summary/facets_summary.install +24 −0 Original line number Diff line number Diff line Loading @@ -5,7 +5,10 @@ * Update hooks for the facets summary module. */ use Drupal\Core\Config\Entity\ConfigEntityUpdater; use Drupal\facets_summary\Entity\FacetsSummary; use Drupal\facets_summary\FacetsSummaryInterface; use Drupal\facets_summary\Plugin\facets_summary\processor\ResetFacetsProcessor; /** * Convert summaries on Search Api facet sources to use the display plugin. Loading @@ -26,3 +29,24 @@ function facets_summary_update_8001() { } } } /** * Set reset link position default value for all existing Facet summary. */ function facets_summary_update_8002(&$sandbox = NULL) { \Drupal::classResolver(ConfigEntityUpdater::class)->update($sandbox, 'facets_summary', function ($facets_summary) { $update = FALSE; if ($facets_summary instanceof FacetsSummaryInterface) { $processor_settings = $facets_summary->getProcessorConfigs(); if (isset($processor_settings['reset_facets'])) { $processor_settings['reset_facets']['settings']['position'] = ResetFacetsProcessor::POSITION_BEFORE; $facets_summary->addProcessor($processor_settings['reset_facets']); $update = TRUE; } } return $update; }); }
modules/facets_summary/src/Plugin/facets_summary/processor/ResetFacetsProcessor.php +45 −2 Original line number Diff line number Diff line Loading @@ -23,6 +23,21 @@ use Drupal\facets_summary\Processor\ProcessorPluginBase; */ class ResetFacetsProcessor extends ProcessorPluginBase implements BuildProcessorInterface { /** * Indicates that reset link should be positioned before facet links. */ const POSITION_BEFORE = 'before'; /** * Indicates that reset link should be positioned after facet links. */ const POSITION_AFTER = 'after'; /** * Indicates that reset link should replace facet links. */ const POSITION_REPLACE = 'replace'; /** * {@inheritdoc} */ Loading Loading @@ -93,7 +108,20 @@ class ResetFacetsProcessor extends ProcessorPluginBase implements BuildProcessor 'facet-summary-item--clear', ], ]; // Place link at necessary position. if ($configuration['settings']['position'] == static::POSITION_BEFORE) { array_unshift($build['#items'], $item); } elseif ($configuration['settings']['position'] == static::POSITION_AFTER) { $build['#items'][] = $item; } else { $build['#items'] = [ $item, ]; } return $build; } Loading @@ -110,6 +138,18 @@ class ResetFacetsProcessor extends ProcessorPluginBase implements BuildProcessor '#default_value' => $config['link_text'], ]; $build['position'] = [ '#type' => 'select', '#options' => [ static::POSITION_BEFORE => $this->t('Show reset link before facets links'), static::POSITION_AFTER => $this->t('Show reset link after facets links'), static::POSITION_REPLACE => $this->t('Show only reset link'), ], '#title' => $this->t('Position'), '#description' => $this->t('Set position of the link to display it before, after or instead of facets links.'), '#default_value' => $config['position'], ]; return $build; } Loading @@ -117,7 +157,10 @@ class ResetFacetsProcessor extends ProcessorPluginBase implements BuildProcessor * {@inheritdoc} */ public function defaultConfiguration() { return ['link_text' => '']; return [ 'link_text' => '', 'position' => static::POSITION_BEFORE, ]; } }
modules/facets_summary/tests/src/Functional/IntegrationTest.php +13 −2 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ namespace Drupal\Tests\facets_summary\Functional; use Drupal\Tests\facets\Functional\FacetsTestBase; use Drupal\facets_summary\Entity\FacetsSummary; use Drupal\facets_summary\Plugin\facets_summary\processor\ResetFacetsProcessor; use Drupal\views\Views; /** Loading Loading @@ -395,9 +396,14 @@ class IntegrationTest extends FacetsTestBase { $this->assertSession()->pageTextContains($this->t('Facets Summary Owl has been updated.')); $this->assertSession()->fieldExists('facets_summary_settings[reset_facets][settings][link_text]'); $this->submitForm(['facets_summary_settings[reset_facets][settings][link_text]' => 'Reset facets'], 'Save'); $this->assertSession()->fieldExists('facets_summary_settings[reset_facets][settings][position]'); $this->submitForm([ 'facets_summary_settings[reset_facets][settings][link_text]' => 'Reset facets', 'facets_summary_settings[reset_facets][settings][position]' => ResetFacetsProcessor::POSITION_BEFORE, ], 'Save'); $this->assertSession()->pageTextContains($this->t('Facets Summary Owl has been updated.')); $this->assertSession()->fieldValueEquals('facets_summary_settings[reset_facets][settings][link_text]', 'Reset facets'); $this->assertSession()->fieldValueEquals('facets_summary_settings[reset_facets][settings][position]', ResetFacetsProcessor::POSITION_BEFORE); } /** Loading Loading @@ -483,7 +489,10 @@ class IntegrationTest extends FacetsTestBase { 'reset_facets' => [ 'processor_id' => 'reset_facets', 'weights' => ['build' => -10], 'settings' => ['link_text' => 'Reset facets'], 'settings' => [ 'link_text' => 'Reset facets', 'position' => ResetFacetsProcessor::POSITION_BEFORE, ], ], ], ])->save(); Loading Loading @@ -564,6 +573,7 @@ class IntegrationTest extends FacetsTestBase { 'facets[keywords][weight]' => 1, 'facets_summary_settings[reset_facets][status]' => 1, 'facets_summary_settings[reset_facets][settings][link_text]' => 'Reset', 'facets_summary_settings[reset_facets][settings][position]' => ResetFacetsProcessor::POSITION_BEFORE, ]; $this->drupalGet('admin/config/search/facets/facet-summary/kepler/edit'); $this->submitForm($summaries, 'Save'); Loading Loading @@ -612,6 +622,7 @@ class IntegrationTest extends FacetsTestBase { 'facets[orval][weight]' => 0, 'facets_summary_settings[reset_facets][status]' => 1, 'facets_summary_settings[reset_facets][settings][link_text]' => 'Reset', 'facets_summary_settings[reset_facets][settings][position]' => ResetFacetsProcessor::POSITION_BEFORE, ]; $this->drupalGet('admin/config/search/facets/facet-summary/trappist/edit'); $this->submitForm($summaries, 'Save'); Loading
modules/facets_summary/tests/src/Unit/Plugin/Processor/ResetFacetsProcessorTest.php +10 −2 Original line number Diff line number Diff line Loading @@ -34,7 +34,12 @@ class ResetFacetsProcessorTest extends UnitTestCase { $container->set('string_translation', $string_translation->reveal()); \Drupal::setContainer($container); $this->processor = new ResetFacetsProcessor(['settings' => ['link_text' => 'Text']], 'reset_facets', []); $this->processor = new ResetFacetsProcessor([ 'settings' => [ 'link_text' => 'Text', 'position' => ResetFacetsProcessor::POSITION_BEFORE, ], ], 'reset_facets', []); } /** Loading Loading @@ -66,7 +71,10 @@ class ResetFacetsProcessorTest extends UnitTestCase { $config = [ 'processor_id' => 'reset_facets', 'weights' => [], 'settings' => ['link_text' => 'Text'], 'settings' => [ 'link_text' => 'Text', 'position' => ResetFacetsProcessor::POSITION_BEFORE, ], ]; $summary->addProcessor($config); Loading
src/Plugin/facets/processor/HierarchyProcessor.php +1 −1 File changed.Contains only whitespace changes. Show changes