diff --git a/src/Entity/Facet.php b/src/Entity/Facet.php index ab04f0f..769da48 100644 --- a/src/Entity/Facet.php +++ b/src/Entity/Facet.php @@ -43,7 +43,7 @@ use Drupal\facets\FacetInterface; * "facet_source_id", * "widget", * "widget_configs", - * "options", + * "query_operator", * "only_visible_when_facet_source_is_visible", * "processor_configs", * "empty_behavior", @@ -103,13 +103,11 @@ class Facet extends ConfigEntityBase implements FacetInterface { protected $widget_configs; /** - * An array of options configuring this facet. + * The operator to hand over to the query, currently AND | OR. * - * @var array - * - * @see getOptions() + * @var string */ - protected $options = array(); + protected $query_operator; /** * The field identifier. @@ -306,7 +304,7 @@ class Facet extends ConfigEntityBase implements FacetInterface { if (!isset($this->processors)) { /* @var $processor_plugin_manager \Drupal\facets\Processor\ProcessorPluginManager */ $processor_plugin_manager = \Drupal::service('plugin.manager.facets.processor'); - $processor_settings = $this->getOption('processors', []); + $processor_settings = !empty($this->processor_configs) ? $this->processor_configs : []; foreach ($processor_plugin_manager->getDefinitions() as $name => $processor_definition) { if (class_exists($processor_definition['class']) && empty($this->processors[$name])) { @@ -347,8 +345,15 @@ class Facet extends ConfigEntityBase implements FacetInterface { /** * {@inheritdoc} */ + public function setQueryOperator($operator = '') { + return $this->query_operator = $operator; + } + + /** + * {@inheritdoc} + */ public function getQueryOperator() { - return $this->getOption('query_operator', 'OR'); + return $this->query_operator ?: 'OR'; } /** @@ -379,36 +384,6 @@ class Facet extends ConfigEntityBase implements FacetInterface { /** * {@inheritdoc} */ - public function getOption($name, $default = NULL) { - return isset($this->options[$name]) ? $this->options[$name] : $default; - } - - /** - * {@inheritdoc} - */ - public function getOptions() { - return $this->options; - } - - /** - * {@inheritdoc} - */ - public function setOption($name, $option) { - $this->options[$name] = $option; - return $this; - } - - /** - * {@inheritdoc} - */ - public function setOptions(array $options) { - $this->options = $options; - return $this; - } - - /** - * {@inheritdoc} - */ public function getFieldIdentifier() { return $this->field_identifier; } @@ -421,8 +396,6 @@ class Facet extends ConfigEntityBase implements FacetInterface { return $this; } - - /** * {@inheritdoc} */ @@ -607,7 +580,7 @@ class Facet extends ConfigEntityBase implements FacetInterface { $processors = $this->loadProcessors(); // Filter processors by status if required. Enabled processors are those - // which have settings in the "processors" option. + // which have settings in the processor_configs. if ($only_enabled) { $processors_settings = !empty($this->processor_configs) ? $this->processor_configs : []; $processors = array_intersect_key($processors, $processors_settings); @@ -724,6 +697,4 @@ class Facet extends ConfigEntityBase implements FacetInterface { return $this->facet_configs; } - - } diff --git a/src/FacetInterface.php b/src/FacetInterface.php index 1d86289..079f59d 100644 --- a/src/FacetInterface.php +++ b/src/FacetInterface.php @@ -170,53 +170,6 @@ interface FacetInterface extends ConfigEntityInterface { public function getUrlProcessorName(); /** - * Retrieves an option. - * - * @param string $name - * The name of an option. - * @param mixed $default - * The value return if the option wasn't set. - * - * @return mixed - * The value of the option. - * - * @see getOptions() - */ - public function getOption($name, $default = NULL); - - /** - * Retrieves an array of all options. - * - * @return array - * An associative array of option values, keyed by the option name. - */ - public function getOptions(); - - /** - * Sets an option. - * - * @param string $name - * The name of an option. - * @param mixed $option - * The new option. - * - * @return $this - * Returns self. - */ - public function setOption($name, $option); - - /** - * Sets the index's options. - * - * @param array $options - * The new index options. - * - * @return $this - * Returns self. - */ - public function setOptions(array $options); - - /** * Sets a string representation of the Facet source plugin. * * This is usually the name of the Search-api view. @@ -230,6 +183,14 @@ interface FacetInterface extends ConfigEntityInterface { public function setFacetSourceId($facet_source_id); /** + * Set the query operator. + * + * @param string + * The query operator being used. + */ + public function setQueryOperator($operator); + + /** * Returns the Facet source id. * * @return string diff --git a/src/Form/FacetDisplayForm.php b/src/Form/FacetDisplayForm.php index 1c4d701..2bf4e5d 100644 --- a/src/Form/FacetDisplayForm.php +++ b/src/Form/FacetDisplayForm.php @@ -536,7 +536,7 @@ class FacetDisplayForm extends EntityForm { } $facet->setEmptyBehavior($empty_behavior_config); - $facet->setOption('query_operator', $form_state->getValue(['facet_settings', 'query_operator'])); + $facet->setQueryOperator($form_state->getValue(['facet_settings', 'query_operator'])); $facet->save(); drupal_set_message(t('Facet %name has been updated.', ['%name' => $facet->getName()])); diff --git a/tests/src/Unit/Plugin/processor/ExcludeSpecifiedItemsProcessorTest.php b/tests/src/Unit/Plugin/processor/ExcludeSpecifiedItemsProcessorTest.php index a6c9762..71870f9 100644 --- a/tests/src/Unit/Plugin/processor/ExcludeSpecifiedItemsProcessorTest.php +++ b/tests/src/Unit/Plugin/processor/ExcludeSpecifiedItemsProcessorTest.php @@ -83,14 +83,6 @@ class ExcludeSpecifiedItemsProcessorTest extends UnitTestCase { public function testNoFilter() { $facet = new Facet([], 'facet'); $facet->setResults($this->originalResults); - $facet->setOption('processors', [ - 'exclude_specified_items' => [ - 'settings' => [ - 'exclude' => 'alpaca', - 'regex' => 0, - ], - ], - ]); $facet->addProcessor([ 'processor_id' => 'exclude_specified_items', 'weights' => [], @@ -114,14 +106,6 @@ class ExcludeSpecifiedItemsProcessorTest extends UnitTestCase { public function testStringFilter() { $facet = new Facet([], 'facet'); $facet->setResults($this->originalResults); - $facet->setOption('processors', [ - 'exclude_specified_items' => [ - 'settings' => [ - 'exclude' => 'llama', - 'regex' => 0, - ], - ], - ]); $facet->addProcessor([ 'processor_id' => 'exclude_specified_items', 'weights' => [], @@ -151,14 +135,6 @@ class ExcludeSpecifiedItemsProcessorTest extends UnitTestCase { public function testRegexFilter($regex, $expected_results) { $facet = new Facet([], 'facet'); $facet->setResults($this->originalResults); - $facet->setOption('processors', [ - 'exclude_specified_items' => [ - 'settings' => [ - 'exclude' => $regex, - 'regex' => 1, - ], - ], - ]); $facet->addProcessor([ 'processor_id' => 'exclude_specified_items', 'weights' => [],