public function FacConfigForm::save in Fast Autocomplete 8
Form submission handler for the 'save' action.
Normally this method should be overridden to provide specific messages to the user and redirect the form after the entity has been saved.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
int Either SAVED_NEW or SAVED_UPDATED, depending on the operation performed.
Overrides EntityForm::save
File
- src/
Form/ FacConfigForm.php, line 326
Class
- FacConfigForm
- Class FacConfigForm.
Namespace
Drupal\fac\FormCode
public function save(array $form, FormStateInterface $form_state) {
/** @var \Drupal\fac\Entity\FacConfig $fac_config */
$fac_config = $this->entity;
$fac_config
->set('searchPluginId', $form_state
->getValue([
'plugin',
'search_plugin_id',
]));
$plugin_config = $form_state
->getValue([
'plugin',
'config',
]);
$fac_config
->set('searchPluginConfig', json_encode($plugin_config));
$fac_config
->set('inputSelectors', $form_state
->getValue('input_selectors'));
$fac_config
->set('numberOfResults', $form_state
->getValue('number_of_results'));
$fac_config
->set('emptyResult', $form_state
->getValue('empty_result'));
$fac_config
->set('allResultsLink', $form_state
->getValue('all_results_link'));
$fac_config
->set('allResultsLinkThreshold', $form_state
->getValue('all_results_link_threshold'));
$fac_config
->set('viewMode', $form_state
->getValue('view_mode'));
$view_modes = $this->entityDisplayRepository
->getAllViewModes();
$selected_view_modes = [];
$entity_type_ids = array_keys($view_modes);
foreach ($entity_type_ids as $entity_type_id) {
$selected_view_modes[$entity_type_id] = $form_state
->getValue('view_mode_' . $entity_type_id);
}
$fac_config
->set('viewModes', $selected_view_modes);
$fac_config
->set('keyMinLength', $form_state
->getValue('key_min_length'));
$fac_config
->set('keyMaxLength', $form_state
->getValue('key_max_length'));
$fac_config
->set('breakpoint', $form_state
->getValue('breakpoint'));
$fac_config
->set('resultLocation', $form_state
->getValue('result_location'));
$fac_config
->set('highlightingEnabled', $form_state
->getValue('highlighting_enabled'));
$fac_config
->set('anonymousSearch', $form_state
->getValue('anonymous_search'));
$fac_config
->set('cleanUpFiles', $form_state
->getValue('clean_up_files'));
$fac_config
->set('filesExpiryTime', $form_state
->getValue('files_expiry_time'));
$status = $fac_config
->save();
if ($status) {
$this
->messenger()
->addStatus($this
->t('Saved the %label Example.', [
'%label' => $fac_config
->label(),
]));
}
else {
$this
->messenger()
->addStatus($this
->t('The %label Fast Autocomplete configuration was not saved.', [
'%label' => $fac_config
->label(),
]));
}
$form_state
->setRedirect('entity.fac_config.collection');
}