public function MessageTemplateForm::save in Message 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/ MessageTemplateForm.php, line 173
Class
- MessageTemplateForm
- Form controller for node type forms.
Namespace
Drupal\message\FormCode
public function save(array $form, FormStateInterface $form_state) {
// Sort by weight.
$text = $form_state
->getValue('text');
usort($text, function ($a, $b) {
return SortArray::sortByKeyInt($a, $b, '_weight');
});
// Do not store weight, as these are now sorted.
$text = array_map(function ($a) {
unset($a['_weight']);
return $a;
}, $text);
$this->entity
->set('text', $text);
parent::save($form, $form_state);
$params = [
'@template' => $form_state
->getValue('label'),
];
$this
->messenger()
->addMessage($this
->t('The message template @template created successfully.', $params));
$form_state
->setRedirect('message.overview_templates');
return $this->entity;
}