Commit 23a0638c authored by ChristianAdamski's avatar ChristianAdamski Committed by borisson_

Issue #2656226 by ChristianAdamski, borisson_: Remove set|getOption from Facet...

Issue #2656226 by ChristianAdamski, borisson_: Remove set|getOption from Facet Entity et al. and fix schema
parent 5c49f5a2
......@@ -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'
......
......@@ -11,7 +11,7 @@ facets.facet_source.*:
name:
type: label
label: Name'
filterKey:
filter_key:
type: string
label: 'Filter key'
url_processor:
......
......@@ -40,3 +40,13 @@ plugin.plugin_configuration.facets_processor.count_limit:
maximum_items:
type: integer
label: 'Maximum amount of items to show.'
# There are no settings intended for this, this will probably always be an empty
# array but not having a schema available means the facet config is not correct.
# This is important because the tests use strict config validation.
plugin.plugin_configuration.facets_processor.url_processor_handler:
type: sequence
label: 'URL processor settings'
sequence:
type: string
label: 'Single settings'
......@@ -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])) {
......@@ -353,11 +351,18 @@ class Facet extends ConfigEntityBase implements FacetInterface {
return $widget->getQueryType($query_types);
}
/**
* {@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';
}
/**
......@@ -385,36 +390,6 @@ class Facet extends ConfigEntityBase implements FacetInterface {
return $this->active_values;
}
/**
* {@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}
*/
......@@ -430,8 +405,6 @@ class Facet extends ConfigEntityBase implements FacetInterface {
return $this;
}
/**
* {@inheritdoc}
*/
......@@ -616,7 +589,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);
......@@ -733,6 +706,4 @@ class Facet extends ConfigEntityBase implements FacetInterface {
return $this->facet_configs;
}
}
......@@ -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;
}
}
......@@ -169,53 +169,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.
*
......@@ -229,6 +182,14 @@ interface FacetInterface extends ConfigEntityInterface {
*/
public function setFacetSourceId($facet_source_id);
/**
* Sets the query operator.
*
* @param string
* The query operator being used.
*/
public function setQueryOperator($operator);
/**
* Returns the Facet source id.
*
......
......@@ -537,7 +537,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()]));
......
......@@ -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,
......
......@@ -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(),
......
......@@ -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.
......
......@@ -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']);
}
......
......@@ -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'));
......
......@@ -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' => [],
......
......@@ -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'
);
......
......@@ -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');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment