Commit 13e98827 authored by borisson_'s avatar borisson_

Refactor FacetForm - moved some code around.

parent c3cf0717
......@@ -53,11 +53,6 @@ class FacetForm extends EntityForm {
*/
protected $processorPluginManager;
/**
* @var array
*/
protected $facetSourcePlugins;
/**
* The plugin manager for facet sources.
*
......@@ -365,6 +360,34 @@ class FacetForm extends EntityForm {
];
}
/**
* Form submission handler for the facet source subform.
*/
public function submitAjaxFacetSourceConfigForm($form, FormStateInterface $form_state) {
$form_state->setRebuild();
}
/**
* Form submission handler for the empty behavior subform.
*/
public function submitAjaxEmptyBehaviorConfigForm($form, FormStateInterface $form_state) {
$form_state->setRebuild();
}
/**
* Form submission handler for the widget subform.
*/
public function submitAjaxWidgetConfigForm($form, FormStateInterface $form_state) {
$form_state->setRebuild();
}
/**
* Handles changes to the selected facet sources.
*/
public function buildAjaxFacetSourceConfigForm(array $form, FormStateInterface $form_state) {
return $form['facet_source_configs'];
}
/**
* Handles changes to the selected widgets.
*/
......@@ -379,6 +402,31 @@ class FacetForm extends EntityForm {
return $form['empty_behavior_configs'];
}
/**
* Builds the configuration forms for all possible facet sources.
*
* @param array $form
* An associative array containing the initial structure of the plugin form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the complete form.
*/
public function buildFacetSourceConfigForm(array &$form, FormStateInterface $form_state) {
$facet_source_id = $this->getEntity()->getFacetSourceId();
if (!is_null($facet_source_id) && $facet_source_id !== '') {
/** @var \Drupal\facetapi\FacetSource\FacetSourceInterface $facet_source */
$facet_source = $this->getFacetSourcePluginManager()->createInstance($facet_source_id);
if ($config_form = $facet_source->buildConfigurationForm([], $form_state, $this->getEntity(), $facet_source)) {
$form['facet_source_configs'][$facet_source_id]['#type'] = 'details';
$form['facet_source_configs'][$facet_source_id]['#title'] = $this->t('Configure %plugin facet source', ['%plugin' => $facet_source->getPluginDefinition()['label']]);
$form['facet_source_configs'][$facet_source_id]['#open'] = TRUE;
$form['facet_source_configs'][$facet_source_id] += $config_form;
}
}
}
/**
* Builds the configuration forms for all selected widgets.
*
......@@ -446,59 +494,6 @@ class FacetForm extends EntityForm {
}
}
/**
* Builds the configuration forms for all possible facet sources.
*
* @param array $form
* An associative array containing the initial structure of the plugin form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the complete form.
*/
public function buildFacetSourceConfigForm(array &$form, FormStateInterface $form_state) {
$facet_source_id = $this->getEntity()->getFacetSourceId();
if (!is_null($facet_source_id) && $facet_source_id !== '') {
/** @var \Drupal\facetapi\FacetSource\FacetSourceInterface $facet_source */
$facet_source = $this->getFacetSourcePluginManager()->createInstance($facet_source_id);
if ($config_form = $facet_source->buildConfigurationForm([], $form_state, $this->getEntity(), $facet_source)) {
$form['facet_source_configs'][$facet_source_id]['#type'] = 'details';
$form['facet_source_configs'][$facet_source_id]['#title'] = $this->t('Configure %plugin facet source', ['%plugin' => $facet_source->getPluginDefinition()['label']]);
$form['facet_source_configs'][$facet_source_id]['#open'] = TRUE;
$form['facet_source_configs'][$facet_source_id] += $config_form;
}
}
}
/**
* Form submission handler for the facet source subform.
*/
public function submitAjaxFacetSourceConfigForm($form, FormStateInterface $form_state) {
$form_state->setRebuild();
}
/**
* Handles changes to the selected facet sources.
*/
public function buildAjaxFacetSourceConfigForm(array $form, FormStateInterface $form_state) {
return $form['facet_source_configs'];
}
/**
* Form submission handler for the empty behavior subform.
*/
public function submitAjaxEmptyBehaviorConfigForm($form, FormStateInterface $form_state) {
$form_state->setRebuild();
}
/**
* Form submission handler for the widget subform.
*/
public function submitAjaxWidgetConfigForm($form, FormStateInterface $form_state) {
$form_state->setRebuild();
}
/**
* {@inheritdoc}
*/
......@@ -520,7 +515,7 @@ class FacetForm extends EntityForm {
// On facet creation, enable all locked processors by default, using their
// default settings.
$initial_settings = [];
$stages = $this->processorPluginManager->getProcessingStages();
$stages = $this->getProcessorPluginManager()->getProcessingStages();
foreach ($facet->getProcessors() as $processor_id => $processor) {
if ($processor->isLocked()) {
$weights = [];
......
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