public function GridStackForm::save in GridStack 8
Overrides Drupal\Core\Entity\EntityFormController::save().
Overrides EntityForm::save
File
- modules/
gridstack_ui/ src/ Form/ GridStackForm.php, line 888
Class
- GridStackForm
- Extends base form for gridstack instance configuration form.
Namespace
Drupal\gridstack_ui\FormCode
public function save(array $form, FormStateInterface $form_state) {
parent::save($form, $form_state);
$entity = $this->entity;
// Prevent leading and trailing spaces in gridstack names.
$entity
->set('label', trim($entity
->label()));
$entity
->set('id', $entity
->id());
$enable = $entity
->id() == 'default' ? FALSE : TRUE;
$entity
->setStatus($enable);
$status = $entity
->save();
$label = $entity
->label();
$edit_link = $entity
->toLink($this
->t('Edit'), 'edit-form')
->toString();
$config_prefix = $entity
->getEntityType()
->getConfigPrefix();
$message = [
'@config_prefix' => $config_prefix,
'%label' => $label,
];
$notice = [
'@config_prefix' => $config_prefix,
'%label' => $label,
'link' => $edit_link,
];
if ($status == SAVED_UPDATED) {
// If we edited an existing entity.
// @todo #2278383.
$this->messenger
->addMessage($this
->t('@config_prefix %label has been updated.', $message));
$this
->logger('gridstack')
->notice('@config_prefix %label has been updated.', $notice);
}
else {
// If we created a new entity.
$this->messenger
->addMessage($this
->t('@config_prefix %label has been added.', $message));
$this
->logger('gridstack')
->notice('@config_prefix %label has been added.', $notice);
}
$form_state
->setRedirectUrl($entity
->toUrl('collection'));
}