You are here

public function SlickFormBase::save in Slick Carousel 8

Same name and namespace in other branches
  1. 8.2 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

1 call to SlickFormBase::save()
SlickForm::save in slick_ui/src/Form/SlickForm.php
Overrides Drupal\Core\Entity\EntityFormController::save().
1 method overrides SlickFormBase::save()
SlickForm::save in slick_ui/src/Form/SlickForm.php
Overrides Drupal\Core\Entity\EntityFormController::save().

File

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

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) {
  $slick = $this->entity;

  // Prevent leading and trailing spaces in slick names.
  $slick
    ->set('label', trim($slick
    ->label()));
  $slick
    ->set('id', $slick
    ->id());
  $status = $slick
    ->save();
  $label = $slick
    ->label();
  $edit_link = $slick
    ->toLink($this
    ->t('Edit'), 'edit-form')
    ->toString();
  $config_prefix = $slick
    ->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.
    drupal_set_message($this
      ->t('@config_prefix %label has been updated.', $message));
    $this
      ->logger('slick')
      ->notice('@config_prefix %label has been updated.', $notice);
  }
  else {

    // If we created a new entity.
    drupal_set_message($this
      ->t('@config_prefix %label has been added.', $message));
    $this
      ->logger('slick')
      ->notice('@config_prefix %label has been added.', $notice);
  }
}