You are here

public function BlazyEntityFormBase::save in Blazy 8.2

Overrides Drupal\Core\Entity\EntityFormController::save().

@todo revert #1497268, or use config_update instead.

Overrides EntityForm::save

File

blazy_ui/src/Form/BlazyEntityFormBase.php, line 100

Class

BlazyEntityFormBase
Provides base form for a entity instance configuration form.

Namespace

Drupal\blazy_ui\Form

Code

public function save(array $form, FormStateInterface $form_state) {
  $optionset = $this->entity;

  // Prevent leading and trailing spaces in slick names.
  $optionset
    ->set('label', trim($optionset
    ->label()));
  $optionset
    ->set('id', $optionset
    ->id());
  $status = $optionset
    ->save();
  $label = $optionset
    ->label();
  $edit_link = $optionset
    ->toLink($this
    ->t('Edit'), 'edit-form')
    ->toString();
  $config_prefix = $optionset
    ->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(static::$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(static::$machineName)
      ->notice('@config_prefix %label has been added.', $notice);
  }
  $form_state
    ->setRedirectUrl($this->entity
    ->toUrl('collection'));
}