public function ManageSortFieldsForm::submitForm in Search API Sorts Widget 1.x
Form submission handler.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides FormInterface::submitForm
File
- src/
Form/ ManageSortFieldsForm.php, line 351
Class
- ManageSortFieldsForm
- Provides a form for managing sort fields for a search api display.
Namespace
Drupal\search_api_sorts_widget\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$status = $form_state
->getValue('status');
$autosubmit = $form_state
->getValue('autosubmit');
$autosubmit_hide = $form_state
->getValue('autosubmit_hide');
$display_id = $this
->getEscapedConfigId($this->display
->getPluginId());
$search_api_sorts_widget = $this
->getSettings();
$search_api_sorts_widget
->set('id', $display_id);
$search_api_sorts_widget
->set('display_id', $display_id);
$search_api_sorts_widget
->set('status', $status);
$search_api_sorts_widget
->set('autosubmit', $autosubmit);
$search_api_sorts_widget
->set('autosubmit_hide', $autosubmit_hide);
$search_api_sorts_widget
->set('sorts', $form_state
->getValue('sorts'));
$search_api_sorts_widget
->save();
// foreach ($form_state->getValue('sorts') as $key => $v) {
// $config_id = $this->getEscapedConfigId($this->display->getPluginId()) . '_' . $key;
// $search_api_sorts_widget = NULL;
// if (isset($search_api_sorts_widgets[$config_id])) {
// // If the field sort is not enabled, delete the config if it exists.
// if ($v['status'] == 0) {
// $search_api_sorts_widgets[$config_id]->delete();
// }
// else {
// $search_api_sorts_widget = $search_api_sorts_widgets[$config_id];
// }
// }
// else {
// // Create configs only for enabled sort fields.
// if ($v['status'] == 1) {
// $search_api_sorts_widget = SearchApiSortsField::create(['langcode' => $this->languageManager->getDefaultLanguage()->getId()]);
// $search_api_sorts_widget->set('id', $config_id);
// $search_api_sorts_widget->set('field_identifier', $key);
// $search_api_sorts_widget->set('display_id', $this->getEscapedConfigId($this->display->getPluginId()));
// }
// }
// // Set all fields from the form to enabled configs only and save the
// // config.
// if ($v['status'] == 1) {
// $search_api_sorts_widget->set('status', $v['status']);
// $search_api_sorts_widget->set('default_sort', $form_state->getValue('default_sort') == $key);
// $search_api_sorts_widget->set('default_order', $v['default_order']);
// $search_api_sorts_widget->set('label', $v['label']);
// $search_api_sorts_widget->set('weight', $v['weight']);
// $search_api_sorts_widget->save();
// }
// }
$this
->messenger()
->addStatus($this
->t('The changes were successfully saved.'));
}