diff --git a/config/schema/facets.facet.schema.yml b/config/schema/facets.facet.schema.yml index 43c0bd8..d1f1d90 100644 --- a/config/schema/facets.facet.schema.yml +++ b/config/schema/facets.facet.schema.yml @@ -26,6 +26,9 @@ facets.facet.*: query_type_name: type: string label: 'Query Type Name' + query_operator: + type: string + label: 'Query Operator' widget: type: string label: 'Widget identifier' diff --git a/config/schema/facets.facetsource.schema.yml b/config/schema/facets.facetsource.schema.yml index 8cf0e35..f24c338 100644 --- a/config/schema/facets.facetsource.schema.yml +++ b/config/schema/facets.facetsource.schema.yml @@ -11,7 +11,7 @@ facets.facet_source.*: name: type: label label: Name' - filterKey: + filter_key: type: string label: 'Filter key' url_processor: diff --git a/config/schema/facets.processor.schema.yml b/config/schema/facets.processor.schema.yml index cc5c7e7..9dc67d3 100644 --- a/config/schema/facets.processor.schema.yml +++ b/config/schema/facets.processor.schema.yml @@ -40,3 +40,11 @@ plugin.plugin_configuration.facets_processor.count_limit: maximum_items: type: integer label: 'Maximum amount of items to show.' + +# There are no settings intended. So probably always an empty array. +plugin.plugin_configuration.facets_processor.url_processor_handler: + type: sequence + label: 'URL processor settings' + sequence: + type: string + label: 'Single settings' diff --git a/src/Entity/Facet.php b/src/Entity/Facet.php index ab04f0f..f6b1189 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", @@ -98,18 +98,16 @@ class Facet extends ConfigEntityBase implements FacetInterface { /** * Configuration for the widget. This is a key-value stored array. * - * @var string + * @var array */ - protected $widget_configs; + 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. @@ -192,14 +190,14 @@ class Facet extends ConfigEntityBase implements FacetInterface { * * @var array */ - protected $processor_configs; + protected $processor_configs = []; /** * Additional facet configurations. * * @var array */ - protected $facet_configs; + protected $facet_configs = []; /** * Is the facet only visible when the facet source is only visible. @@ -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/Entity/FacetSource.php b/src/Entity/FacetSource.php index 0ed4cc8..9aa4733 100644 --- a/src/Entity/FacetSource.php +++ b/src/Entity/FacetSource.php @@ -37,8 +37,8 @@ use Drupal\facets\UrlProcessor\UrlProcessorInterface; * config_export = { * "id", * "name", - * "filterKey", - * "urlProcessor" + * "filter_key", + * "url_processor" * }, * links = { * "canonical" = "/admin/config/search/facets/facet-sources/", @@ -67,14 +67,14 @@ class FacetSource extends ConfigEntityBase implements FacetSourceInterface { * * @var string */ - protected $filterKey; + protected $filter_key; /** * The url processor name. * * @var string */ - protected $urlProcessor = 'query_string'; + protected $url_processor = 'query_string'; /** * {@inheritdoc} @@ -94,28 +94,28 @@ class FacetSource extends ConfigEntityBase implements FacetSourceInterface { * {@inheritdoc} */ public function setFilterKey($filter_key) { - $this->filterKey = $filter_key; + $this->filter_key = $filter_key; } /** * {@inheritdoc} */ public function getFilterKey() { - return $this->filterKey; + return $this->filter_key; } /** * {@inheritdoc} */ public function setUrlProcessor($processor_name) { - $this->urlProcessor = $processor_name; + $this->url_processor = $processor_name; } /** * {@inheritdoc} */ public function getUrlProcessorName() { - return $this->urlProcessor; + return $this->url_processor; } } 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 5a5a04b..138246f 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/src/Form/FacetSourceEditForm.php b/src/Form/FacetSourceEditForm.php index b8680b5..45b14cc 100644 --- a/src/Form/FacetSourceEditForm.php +++ b/src/Form/FacetSourceEditForm.php @@ -94,7 +94,7 @@ class FacetSourceEditForm extends EntityForm { $facet_source = $this->getEntity(); // Filter key setting. - $form['filterKey'] = [ + $form['filter_key'] = [ '#type' => 'textfield', '#title' => $this->t('Filter key'), '#size' => 20, @@ -112,7 +112,7 @@ class FacetSourceEditForm extends EntityForm { $url_processors[$definition['id']] = $definition['label']; $url_processors_description[] = $definition['description']; } - $form['urlProcessor'] = [ + $form['url_processor'] = [ '#type' => 'radios', '#title' => $this->t('URL Processor'), '#options' => $url_processors, diff --git a/src/Plugin/facets/widget/CheckboxWidget.php b/src/Plugin/facets/widget/CheckboxWidget.php index 27382ab..a202ccd 100644 --- a/src/Plugin/facets/widget/CheckboxWidget.php +++ b/src/Plugin/facets/widget/CheckboxWidget.php @@ -99,7 +99,7 @@ class CheckboxWidget implements WidgetInterface, FormInterface { $results = $facet->getResults(); $configuration = $facet->getWidgetConfigs(); - $show_numbers = (bool) $configuration['show_numbers']; + $show_numbers = (bool) (isset($configuration['show_numbers']) ? $configuration['show_numbers'] : FALSE); $form[$facet->getFieldAlias()] = [ '#type' => 'checkboxes', '#title' => $facet->getName(), diff --git a/src/Plugin/facets/widget/LinksWidget.php b/src/Plugin/facets/widget/LinksWidget.php index 0591f2e..67bc5fb 100644 --- a/src/Plugin/facets/widget/LinksWidget.php +++ b/src/Plugin/facets/widget/LinksWidget.php @@ -42,7 +42,7 @@ class LinksWidget implements WidgetInterface { $items = []; $configuration = $facet->getWidgetConfigs(); - $show_numbers = (bool) $configuration['show_numbers']; + $show_numbers = empty($configuration['show_numbers']) ? FALSE : (bool) $configuration['show_numbers']; foreach ($results as $result) { // Get the link. diff --git a/src/Tests/FacetSourceTest.php b/src/Tests/FacetSourceTest.php index c5f0e15..9bd8f9c 100644 --- a/src/Tests/FacetSourceTest.php +++ b/src/Tests/FacetSourceTest.php @@ -42,16 +42,16 @@ class FacetSourceTest extends FacetWebTestBase { // Test the edit page. $edit = array( - 'filterKey' => 'fq', + 'filter_key' => 'fq', ); - $this->assertField('filterKey'); - $this->assertField('urlProcessor'); + $this->assertField('filter_key'); + $this->assertField('url_processor'); $this->drupalPostForm(NULL, $edit, $this->t('Save')); $this->assertResponse(200); - // Test that saving worked filterkey has the new value - $this->assertField('filterKey'); - $this->assertField('urlProcessor'); + // Test that saving worked filter_key has the new value + $this->assertField('filter_key'); + $this->assertField('url_processor'); $this->assertRaw('fq'); } @@ -69,17 +69,17 @@ class FacetSourceTest extends FacetWebTestBase { // Test the edit page. $edit = array( - 'urlProcessor' => 'dummy_query', + 'url_processor' => 'dummy_query', ); - $this->assertField('filterKey'); - $this->assertField('urlProcessor'); + $this->assertField('filter_key'); + $this->assertField('url_processor'); $this->drupalPostForm(NULL, $edit, $this->t('Save')); $this->assertResponse(200); // Test that saving worked and that the url processor has the new value. - $this->assertField('filterKey'); - $this->assertField('urlProcessor'); - $elements = $this->xpath('//input[@id=:id]', [':id' => 'edit-urlprocessor-dummy-query']); + $this->assertField('filter_key'); + $this->assertField('url_processor'); + $elements = $this->xpath('//input[@id=:id]', [':id' => 'edit-url-processor-dummy-query']); $this->assertEqual('dummy_query', $elements[0]['value']); } diff --git a/src/Tests/UrlIntegrationTest.php b/src/Tests/UrlIntegrationTest.php index 0e150d0..e5ebf98 100644 --- a/src/Tests/UrlIntegrationTest.php +++ b/src/Tests/UrlIntegrationTest.php @@ -95,8 +95,8 @@ class UrlIntegrationTest extends FacetWebTestBase { $this->clickLink($this->t('Configure')); $edit = [ - 'filterKey' => 'y', - 'urlProcessor' => 'query_string', + 'filter_key' => 'y', + 'url_processor' => 'query_string', ]; $this->drupalPostForm(NULL, $edit, $this->t('Save')); @@ -118,8 +118,8 @@ class UrlIntegrationTest extends FacetWebTestBase { $this->clickLink($this->t('Configure')); $edit = [ - 'filterKey' => 'y', - 'urlProcessor' => 'dummy_query', + 'filter_key' => 'y', + 'url_processor' => 'dummy_query', ]; $this->drupalPostForm(NULL, $edit, $this->t('Save')); 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' => [], diff --git a/tests/src/Unit/Plugin/query_type/SearchApiStringTest.php b/tests/src/Unit/Plugin/query_type/SearchApiStringTest.php index 9f15b78..58d5966 100644 --- a/tests/src/Unit/Plugin/query_type/SearchApiStringTest.php +++ b/tests/src/Unit/Plugin/query_type/SearchApiStringTest.php @@ -25,7 +25,7 @@ class SearchApiStringTest extends UnitTestCase { public function testQueryType() { $query = new SearchApiQuery([], 'search_api_query', []); $facet = new Facet( - ['options' => ['query_operator' => 'AND']], + ['query_operator' => 'AND'], 'facets_facet' ); diff --git a/tests/src/Unit/Plugin/url_processor/QueryStringTest.php b/tests/src/Unit/Plugin/url_processor/QueryStringTest.php index df418fb..7f30653 100644 --- a/tests/src/Unit/Plugin/url_processor/QueryStringTest.php +++ b/tests/src/Unit/Plugin/url_processor/QueryStringTest.php @@ -170,7 +170,7 @@ class QueryStringTest extends UnitTestCase { * Test that the facet source configuration filter key override works. */ public function testFacetSourceFilterKeyOverride() { - $facet_source = new FacetSource(['filterKey' => 'ab'], 'facets_facet_source'); + $facet_source = new FacetSource(['filter_key' => 'ab'], 'facets_facet_source'); // Override the container with the new facet source. $storage = $this->getMock('\Drupal\Core\Entity\EntityStorageInterface');