public function FormatterForm::save in Custom Formatters 8.3
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/ FormatterForm.php, line 211
Class
- FormatterForm
- Form controller for the shortcut set entity edit forms.
Namespace
Drupal\custom_formatters\FormCode
public function save(array $form, FormStateInterface $form_state) {
$this->entity
->getFormatterType()
->submitForm($form, $form_state);
$entity = $this->entity;
$is_new = !$entity
->getOriginalId();
// Invoke all third party integrations save method.
$this->formatterExtrasManager
->invokeAll('settingsSave', $entity, $form, $form_state);
$entity
->save();
// Clear cached formatters.
// @TODO - Tag custom formatters?
$this->fieldFormatterManager
->clearCachedDefinitions();
if ($is_new) {
$this
->messenger()
->addStatus($this
->t('Added formatter %formatter.', [
'%formatter' => $entity
->label(),
]));
}
else {
$this
->messenger()
->addStatus($this
->t('Updated formatter %formatter.', [
'%formatter' => $entity
->label(),
]));
}
$form_state
->setRedirectUrl(new Url('entity.formatter.collection'));
}