Commit 29abf2a2 authored by borisson_'s avatar borisson_ Committed by borisson_

Issue #2896237 by borisson_, joachim: processor plugins aren't using plugin configuration correctly

parent ddacfe49
......@@ -44,13 +44,12 @@ class BooleanItemProcessor extends ProcessorPluginBase implements BuildProcessor
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state, FacetInterface $facet) {
$processors = $facet->getProcessors();
$config = isset($processors[$this->getPluginId()]) ? $processors[$this->getPluginId()] : NULL;
$config = $this->getConfiguration();
$build['on_value'] = [
'#title' => $this->t('On value'),
'#type' => 'textfield',
'#default_value' => !is_null($config) ? $config->getConfiguration()['on_value'] : $this->defaultConfiguration()['on_value'],
'#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.'),
'#states' => [
'required' => ['input[name="facet_settings[boolean_item][status]"' => ['checked' => TRUE]],
......@@ -60,7 +59,7 @@ class BooleanItemProcessor extends ProcessorPluginBase implements BuildProcessor
$build['off_value'] = [
'#title' => $this->t('Off value'),
'#type' => 'textfield',
'#default_value' => !is_null($config) ? $config->getConfiguration()['off_value'] : $this->defaultConfiguration()['off_value'],
'#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.'),
'#states' => [
'required' => ['input[name="facet_settings[boolean_item][status]"' => ['checked' => TRUE]],
......
......@@ -25,8 +25,7 @@ class CountLimitProcessor extends ProcessorPluginBase implements BuildProcessorI
* {@inheritdoc}
*/
public function build(FacetInterface $facet, array $results) {
$processors = $facet->getProcessors();
$config = $processors[$this->getPluginId()]->getConfiguration();
$config = $this->getConfiguration();
$min_count = $config['minimum_items'];
$max_count = $config['maximum_items'];
......@@ -45,18 +44,17 @@ class CountLimitProcessor extends ProcessorPluginBase implements BuildProcessorI
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state, FacetInterface $facet) {
$processors = $facet->getProcessors();
$config = isset($processors[$this->getPluginId()]) ? $processors[$this->getPluginId()] : NULL;
$config = $this->getConfiguration();
$build['minimum_items'] = [
'#title' => $this->t('Minimum items'),
'#type' => 'number',
'#min' => 1,
'#default_value' => !is_null($config) ? $config->getConfiguration()['minimum_items'] : $this->defaultConfiguration()['minimum_items'],
'#default_value' => $config['minimum_items'],
'#description' => $this->t('Hide block if the facet contains less than this number of results.'),
];
$max_default_value = !is_null($config) ? $config->getConfiguration()['maximum_items'] : $this->defaultConfiguration()['maximum_items'];
$max_default_value = $config['maximum_items'];
$build['maximum_items'] = [
'#title' => $this->t('Maximum items'),
'#type' => 'number',
......
......@@ -80,7 +80,7 @@ class DependentFacetProcessor extends ProcessorPluginBase implements BuildProces
$build = [];
$processors = $current_facet->getProcessors();
$config = isset($processors[$this->getPluginId()]) ? $processors[$this->getPluginId()]->getConfiguration() : NULL;
$config = $this->getConfiguration();
// Loop over all defined blocks and filter them by provider, this builds an
// array of blocks that are provided by the facets module.
......
......@@ -25,13 +25,12 @@ class ExcludeSpecifiedItemsProcessor extends ProcessorPluginBase implements Buil
* {@inheritdoc}
*/
public function build(FacetInterface $facet, array $results) {
$processors = $facet->getProcessors();
$config = $processors[$this->getPluginId()];
$config = $this->getConfiguration();
/** @var \Drupal\facets\Result\ResultInterface $result */
$exclude_item = $config->getConfiguration()['exclude'];
$exclude_item = $config['exclude'];
foreach ($results as $id => $result) {
if ($config->getConfiguration()['regex']) {
if ($config['regex']) {
$matcher = '/' . trim(str_replace('/', '\\/', $exclude_item)) . '/';
if (preg_match($matcher, $result->getRawValue()) || preg_match($matcher, $result->getDisplayValue())) {
unset($results[$id]);
......@@ -55,19 +54,18 @@ class ExcludeSpecifiedItemsProcessor extends ProcessorPluginBase implements Buil
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state, FacetInterface $facet) {
$processors = $facet->getProcessors();
$config = isset($processors[$this->getPluginId()]) ? $processors[$this->getPluginId()] : NULL;
$config = $this->getConfiguration();
$build['exclude'] = [
'#title' => $this->t('Exclude items'),
'#type' => 'textfield',
'#default_value' => !is_null($config) ? $config->getConfiguration()['exclude'] : $this->defaultConfiguration()['exclude'],
'#default_value' => $config['exclude'],
'#description' => $this->t("Comma separated list of titles or values that should be excluded, matching either an item's title or value."),
];
$build['regex'] = [
'#title' => $this->t('Regular expressions used'),
'#type' => 'checkbox',
'#default_value' => !is_null($config) ? $config->getConfiguration()['regex'] : $this->defaultConfiguration()['regex'],
'#default_value' => $config['regex'],
'#description' => $this->t('Interpret each exclude list item as a regular expression pattern.<br /><small>(Slashes are escaped automatically, patterns using a comma can be wrapped in "double quotes", and if such a pattern uses double quotes itself, just make them double-double-quotes (""))</small>.'),
];
......
......@@ -89,7 +89,6 @@ class ProcessorPluginBase extends PluginBase implements ProcessorInterface {
*/
public function getConfiguration() {
unset($this->configuration['facet']);
// TODO: Do we need this here anyway?
return $this->configuration + $this->defaultConfiguration();
}
......
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