public function MetatagViewsEditForm::submitForm in Metatag 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
- metatag_views/
src/ Form/ MetatagViewsEditForm.php, line 158
Class
- MetatagViewsEditForm
- Class MetatagViewsEditForm.
Namespace
Drupal\metatag_views\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
// Get the submitted form values.
$view_name = $form_state
->getValue('view');
list($view_id, $display_id) = explode(':', $view_name);
$metatags = $form_state
->getValues();
unset($metatags['view']);
$metatags = $this
->clearMetatagViewsDisallowedValues($metatags);
/** @var \Drupal\views\ViewEntityInterface $view */
$view = $this->viewsManager
->load($view_id);
// Store the meta tags on the view.
$config_name = $view
->getConfigDependencyName();
$config_path = 'display.' . $display_id . '.display_options.display_extenders.metatag_display_extender.metatags';
// Set configuration values based on form submission. This always edits the
// original language.
$configuration = $this
->configFactory()
->getEditable($config_name);
if (empty($this
->removeEmptyTags($metatags))) {
$configuration
->clear($config_path);
}
else {
$configuration
->set($config_path, $metatags);
}
$configuration
->save();
// Redirect back to the views list.
$form_state
->setRedirect('metatag_views.metatags.list');
$this
->messenger()
->addMessage($this
->t('Metatags for @view : @display have been saved.', [
'@view' => $view
->label(),
'@display' => $view
->getDisplay($display_id)['display_title'],
]));
}