Commit 63314a85 authored by borisson_'s avatar borisson_ Committed by borisson_

Issue #2878849 by borisson_, agoradesign: Processor plugins initialized within...

Issue #2878849 by borisson_, agoradesign: Processor plugins initialized within DefaultFacetManager::alterQuery() are lacking their configuration values
parent 451abbdf
......@@ -235,9 +235,12 @@ class DefaultFacetManager {
if (!$this->preparedFacets && empty($this->facets)) {
$this->facets = $this->getEnabledFacets();
foreach ($this->facets as $facet) {
$processor_configs = $facet->getProcessorConfigs();
foreach ($facet->getProcessorsByStage(ProcessorInterface::STAGE_PRE_QUERY) as $processor) {
$processor_config = $processor_configs[$processor->getPluginDefinition()['id']]['settings'];
$processor_config['facet'] = $facet;
/** @var PreQueryProcessorInterface $pre_query_processor */
$pre_query_processor = $this->processorPluginManager->createInstance($processor->getPluginDefinition()['id'], ['facet' => $facet]);
$pre_query_processor = $this->processorPluginManager->createInstance($processor->getPluginDefinition()['id'], $processor_config);
if (!$pre_query_processor instanceof PreQueryProcessorInterface) {
throw new InvalidProcessorException("The processor {$processor->getPluginDefinition()['id']} has a pre_query definition but doesn't implement the required PreQueryProcessorInterface interface");
}
......
<?php
namespace Drupal\facets_custom_widget\Plugin\facets\processor;
use Drupal\Core\Form\FormStateInterface;
use Drupal\facets\FacetInterface;
use Drupal\facets\Processor\PreQueryProcessorInterface;
use Drupal\facets\Processor\ProcessorPluginBase;
/**
* The URL processor handler triggers the actual url processor.
*
* @FacetsProcessor(
* id = "test_pre_query",
* label = @Translation("test pre query"),
* description = @Translation("TEST pre query"),
* stages = {
* "pre_query" = 50
* }
* )
*/
class TestPreQuery extends ProcessorPluginBase implements PreQueryProcessorInterface {
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state, FacetInterface $facet) {
return [
'test_value' => [
'#type' => 'textfield',
]
];
}
/**
* {@inheritdoc}
*/
public function preQuery(\Drupal\facets\FacetInterface $facet) {
drupal_set_message($this->getConfiguration()['test_value']);
}
}
......@@ -24,6 +24,7 @@ class ProcessorIntegrationTest extends FacetsTestBase {
* {@inheritdoc}
*/
public static $modules = [
'facets_custom_widget',
'options',
];
......@@ -640,4 +641,24 @@ class ProcessorIntegrationTest extends FacetsTestBase {
$this->assertFacetLabel('Basic page');
}
/**
* Test pre query processor.
*/
public function testPreQueryProcessor() {
$facet_name = "Eamus Catuli";
$facet_id = "eamus_catuli";
$editForm = 'admin/config/search/facets/' . $facet_id . '/edit';
$this->createFacet($facet_name, $facet_id);
$edit = [
'facet_settings[test_pre_query][status]' => TRUE,
'facet_settings[test_pre_query][settings][test_value]' => 'Llama',
];
$this->drupalPostForm($editForm, $edit, 'Save');
$this->drupalGet('search-api-test-fulltext');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->pageTextContains('Llama');
}
}
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