public function IndexOverviewForm::submitForm in Search API Autocomplete 8
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/ IndexOverviewForm.php, line 271
Class
- IndexOverviewForm
- Defines the overview of all search autocompletion configurations.
Namespace
Drupal\search_api_autocomplete\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$messages = $this
->t('The settings have been saved.');
foreach ($form_state
->getValue('searches') as $id => $enabled) {
/** @var \Drupal\search_api_autocomplete\SearchInterface $search */
$search = $form_state
->get([
'searches',
$id,
]);
if ($search && $search
->status() != $enabled) {
$change = TRUE;
if ($search
->isNew()) {
$options['query'] = $this->redirectDestination
->getAsArray();
$options['fragment'] = 'module-search_api_autocomplete';
$url = Url::fromRoute('user.admin_permissions', [], $options);
if ($url
->access()) {
$vars[':perm_url'] = $url
->toString();
$messages = $this
->t('The settings have been saved. Please remember to set the <a href=":perm_url">permissions</a> for the newly enabled searches.', $vars);
}
}
$search
->setStatus($enabled);
$search
->save();
}
}
$this->messenger
->addStatus(empty($change) ? $this
->t('No values were changed.') : $messages);
}