diff --git a/src/Entity/Facet.php b/src/Entity/Facet.php index ab04f0f..b29842c 100644 --- a/src/Entity/Facet.php +++ b/src/Entity/Facet.php @@ -329,7 +329,16 @@ class Facet extends ConfigEntityBase implements FacetInterface { } return $this->processors; - } /** + } + + /** + * {@inheritdoc} + */ + public function getProcessorConfigs() { + return $this->processor_configs; + } + + /** * {@inheritdoc} */ public function getQueryType() { diff --git a/src/FacetInterface.php b/src/FacetInterface.php index 1d86289..1406476 100644 --- a/src/FacetInterface.php +++ b/src/FacetInterface.php @@ -293,6 +293,14 @@ interface FacetInterface extends ConfigEntityInterface { public function getProcessorsByStage($stage, $only_enabled = TRUE); /** + * Retrieves this facets's processor configs. + * + * @return array + * An array of processors and their configs. + */ + public function getProcessorConfigs(); + + /** * Sets the "only visible when facet source is visible" boolean flag. * * @param bool $only_visible_when_facet_source_is_visible diff --git a/src/Form/FacetDisplayForm.php b/src/Form/FacetDisplayForm.php index 5a5a04b..5420ce4 100644 --- a/src/Form/FacetDisplayForm.php +++ b/src/Form/FacetDisplayForm.php @@ -393,6 +393,8 @@ class FacetDisplayForm extends EntityForm { ); } + $processor_settings = $facet->getProcessorConfigs(); + // Fill in the containers previously created with the processors that are // enabled on the facet. foreach ($processors_by_stage as $stage => $processors) { @@ -498,9 +500,8 @@ class FacetDisplayForm extends EntityForm { 'weights' => array(), 'settings' => array(), ); - $processor_values = $values[$form_container_key][$processor_id]; - if (!empty($processor_values['weights'])) { - $new_settings['weights'] = $processor_values['weights']; + if (!empty($values['processors'][$processor_id]['weights'])) { + $new_settings['weights'] = $values['processors'][$processor_id]['weights']; } if (isset($form[$form_container_key][$processor_id]['settings'])) { $processor_form_state = new SubFormState( diff --git a/src/Tests/IntegrationTest.php b/src/Tests/IntegrationTest.php index bcb12d2..cc51daa 100644 --- a/src/Tests/IntegrationTest.php +++ b/src/Tests/IntegrationTest.php @@ -401,6 +401,32 @@ class IntegrationTest extends FacetWebTestBase { $this->drupalPostForm(NULL, $form, $this->t('Save')); $this->assertResponse(200); $this->assertFieldChecked('edit-facet-settings-count-limit-status'); + + // Add an extra processor so we can test the weights as well. + $form = [ + 'facet_settings[hide_non_narrowing_result_processor][status]' => TRUE, + 'facet_settings[count_limit][status]' => TRUE, + ]; + $this->drupalPostForm(NULL, $form, $this->t('Save')); + + $this->assertResponse(200); + $this->assertFieldChecked('edit-facet-settings-count-limit-status'); + $this->assertFieldChecked('edit-facet-settings-hide-non-narrowing-result-processor-status'); + $this->assertOptionSelected('edit-processors-count-limit-weights-build', -10); + $this->assertOptionSelected('edit-processors-hide-non-narrowing-result-processor-weights-build', -10); + + // Change the weight of one of the processors and test that the weight + // change persisted. + $form = [ + 'facet_settings[hide_non_narrowing_result_processor][status]' => TRUE, + 'facet_settings[count_limit][status]' => TRUE, + 'processors[hide_non_narrowing_result_processor][weights][build]' => 5, + ]; + $this->drupalPostForm(NULL, $form, $this->t('Save')); + $this->assertFieldChecked('edit-facet-settings-count-limit-status'); + $this->assertFieldChecked('edit-facet-settings-hide-non-narrowing-result-processor-status'); + $this->assertOptionSelected('edit-processors-count-limit-weights-build', -10); + $this->assertOptionSelected('edit-processors-hide-non-narrowing-result-processor-weights-build', 5); } /**