You are here

public function SlickFormBase::save in Slick Carousel 8.2

Same name and namespace in other branches
  1. 8 slick_ui/src/Form/SlickFormBase.php \Drupal\slick_ui\Form\SlickFormBase::save()

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

@todo revert #1497268, or use config_update instead.

Overrides EntityForm::save

File

slick_ui/src/Form/SlickFormBase.php, line 118

Class

SlickFormBase
Provides base form for a slick instance configuration form.

Namespace

Drupal\slick_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'));
}