diff --git a/config/schema/facets.processor.schema.yml b/config/schema/facets.processor.schema.yml index 37c18fa..7a49f54 100644 --- a/config/schema/facets.processor.schema.yml +++ b/config/schema/facets.processor.schema.yml @@ -35,8 +35,12 @@ plugin.plugin_configuration.facets_processor.sort_processor_handler: type: sequence label: 'Facet sort processor configuration.' sequence: - type: plugin.plugin_configuration.facets_sort_processor.[%key] - label: 'Facet plugin options' + processor_id: + type: string + label: 'The plugin ID of the processor' + settings: + type: plugin.plugin_configuration.facets_sort_processor.[%parent.processor_id] + label: 'Facet plugin options' plugin.plugin_configuration.facets_processor.url_processor_handler: type: config_object diff --git a/config/schema/facets.sort_processor.schema.yml b/config/schema/facets.sort_processor.schema.yml index e69de29..b0d5ff9 100644 --- a/config/schema/facets.sort_processor.schema.yml +++ b/config/schema/facets.sort_processor.schema.yml @@ -0,0 +1,31 @@ +plugin.plugin_configuration.facets_sort_processor.raw_value_widget_order: + type: mapping + label: 'Raw value widget order' + mapping: + sort: + type: string + label: sort order + +plugin.plugin_configuration.facets_sort_processor.active_widget_order: + type: mapping + label: 'Active widget order' + mapping: + sort: + type: string + label: sort order + +plugin.plugin_configuration.facets_sort_processor.count_widget_order: + type: mapping + label: 'Active widget order' + mapping: + sort: + type: string + label: sort order + +plugin.plugin_configuration.facets_sort_processor.display_value_widget_order: + type: mapping + label: 'Display value widget order' + mapping: + sort: + type: string + label: sort order diff --git a/src/Form/FacetDisplayForm.php b/src/Form/FacetDisplayForm.php index 3cd08e5..41e4e9b 100644 --- a/src/Form/FacetDisplayForm.php +++ b/src/Form/FacetDisplayForm.php @@ -327,6 +327,10 @@ class FacetDisplayForm extends EntityForm { ), ); $form['facet_sorting'][$processor_id]['settings'] += $processor_form; + $form['facet_sorting'][$processor_id]['processor_id'] = array( + '#type' => 'hidden', + '#value' => $processor_id, + ); // Make sure that settings are saved as expected. if (count($sorting_settings) > 0 && isset($sorting_settings[$processor_id])) { @@ -511,18 +515,17 @@ class FacetDisplayForm extends EntityForm { public function submitForm(array &$form, FormStateInterface $form_state) { $values = $form_state->getValues(); - // Store processor settings. /** @var \Drupal\facets\FacetInterface $facet */ $facet = $this->entity; /** @var \Drupal\facets\Processor\ProcessorInterface $processor */ $processors = $facet->getProcessors(FALSE); foreach ($processors as $processor_id => $processor) { - $form_container_key = $processor instanceof SortProcessorInterface ? 'facet_sorting' : 'facet_settings'; - if (empty($values[$form_container_key][$processor_id]['status'])) { + if (empty($values['facet_settings'][$processor_id]['status'])) { $facet->removeProcessor($processor_id); continue; } + $new_settings = [ 'processor_id' => $processor_id, 'weights' => [], @@ -531,19 +534,11 @@ class FacetDisplayForm extends EntityForm { 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( - $form_state, - array($form_container_key, $processor_id, 'settings') - ); - $processor->submitConfigurationForm($form[$form_container_key][$processor_id]['settings'], $processor_form_state, $facet); - $new_settings['settings'] = $processor->getConfiguration(); - } - // The sort processor handler should have the settings for all sorting - // facets. - if ($processor_id === 'sort_processor_handler') { - $new_settings['settings'] = isset($values['facet_sorting']) ? $values['facet_sorting'] : []; + if (isset($form['facet_settings'][$processor_id]['settings'])) { + $processor_form_state = new SubFormState($form_state, array('facet_settings', $processor_id, 'settings')); + $processor->submitConfigurationForm($form['facet_settings'][$processor_id]['settings'], $processor_form_state, $facet); + $new_settings['settings'] = $processor->getConfiguration(); } $facet->addProcessor($new_settings); } diff --git a/src/Plugin/facets/processor/SortProcessorHandler.php b/src/Plugin/facets/processor/SortProcessorHandler.php index e5167ec..70387a8 100644 --- a/src/Plugin/facets/processor/SortProcessorHandler.php +++ b/src/Plugin/facets/processor/SortProcessorHandler.php @@ -2,6 +2,7 @@ namespace Drupal\facets\Plugin\facets\processor; +use Drupal\Core\Form\FormStateInterface; use Drupal\facets\Exception\InvalidProcessorException; use Drupal\facets\FacetInterface; use Drupal\facets\Processor\BuildProcessorInterface; @@ -47,7 +48,14 @@ class SortProcessorHandler extends ProcessorPluginBase implements BuildProcessor /** @var \Drupal\facets\FacetInterface $facet */ $this->facet = $configuration['facet']; + } + /** + * {@inheritdoc} + */ + public function submitConfigurationForm(array $form, FormStateInterface $form_state, FacetInterface $facet) { + var_dump(func_get_args()); die; + $this->setConfiguration($form_state->getValues()); } /** diff --git a/src/Processor/ProcessorInterface.php b/src/Processor/ProcessorInterface.php index 6b1c4b5..2c9daee 100644 --- a/src/Processor/ProcessorInterface.php +++ b/src/Processor/ProcessorInterface.php @@ -3,6 +3,7 @@ namespace Drupal\facets\Processor; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Plugin\PluginFormInterface; use Drupal\facets\FacetInterface; use Drupal\Component\Plugin\ConfigurablePluginInterface; use Drupal\Component\Plugin\PluginInspectionInterface; @@ -51,6 +52,8 @@ interface ProcessorInterface extends ConfigurablePluginInterface, PluginInspecti */ public function validateConfigurationForm(array $form, FormStateInterface $form_state, FacetInterface $facet); + public function submitConfigurationForm(array $form, FormStateInterface $form_state, FacetInterface $facetInterface); + /** * Checks whether this processor implements a particular stage. * diff --git a/src/SortProcessor/SortProcessorInterface.php b/src/SortProcessor/SortProcessorInterface.php index 844d4a3..16aed63 100644 --- a/src/SortProcessor/SortProcessorInterface.php +++ b/src/SortProcessor/SortProcessorInterface.php @@ -2,6 +2,10 @@ namespace Drupal\facets\SortProcessor; +use Drupal\Component\Plugin\ConfigurablePluginInterface; +use Drupal\Component\Plugin\PluginInspectionInterface; +use Drupal\Core\Form\FormStateInterface; +use Drupal\facets\FacetInterface; use Drupal\facets\Result\Result; /** @@ -12,7 +16,7 @@ use Drupal\facets\Result\Result; * build processor interfaces, those methods are where the bulk of the work * should be done. */ -interface SortProcessorInterface { +interface SortProcessorInterface extends PluginInspectionInterface, ConfigurablePluginInterface { /** * Compares results and returns the result for uasort(). @@ -27,4 +31,30 @@ interface SortProcessorInterface { */ public function sortResults(Result $a, Result $b); + /** + * Adds a configuration form for this processor. + * + * @param array $form + * The form. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * The current form state. + * @param \Drupal\facets\FacetInterface $facet + * The facet this processor is being added to. + */ + public function buildConfigurationForm(array $form, FormStateInterface $form_state, FacetInterface $facet); + + /** + * Validates a configuration form for this processor. + * + * @param array $form + * The form. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * The current form state. + * @param \Drupal\facets\FacetInterface $facet + * The facet this processor is being added to. + */ + public function validateConfigurationForm(array $form, FormStateInterface $form_state, FacetInterface $facet); + + public function submitConfigurationForm(array $form, FormStateInterface $form_state, FacetInterface $facetInterface); + }