public function GridStackFormBase::save in GridStack 8.2
Overrides Drupal\Core\Entity\EntityFormController::save().
Overrides EntityForm::save
1 call to GridStackFormBase::save()
- GridStackVariantForm::save in modules/
gridstack_ui/ src/ Form/ GridStackVariantForm.php - Overrides Drupal\Core\Entity\EntityFormController::save().
1 method overrides GridStackFormBase::save()
- GridStackVariantForm::save in modules/
gridstack_ui/ src/ Form/ GridStackVariantForm.php - Overrides Drupal\Core\Entity\EntityFormController::save().
File
- modules/
gridstack_ui/ src/ Form/ GridStackFormBase.php, line 1023
Class
- GridStackFormBase
- 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', Html::escape(trim($entity
->label())));
$entity
->set('id', $entity
->id());
$entity
->set('description', strip_tags($entity
->description()));
$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($this->machineName)
->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($this->machineName)
->notice('@config_prefix %label has been added.', $notice);
}
$form_state
->setRedirectUrl($entity
->toUrl('collection'));
}