You are here

public function AssetInjectorFormBase::save in Asset Injector 8.2

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

Form submission handler for the 'save' action.

Normally this method should be overridden to provide specific messages to the user and redirect the form after the entity has been saved.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

int Either SAVED_NEW or SAVED_UPDATED, depending on the operation performed.

Overrides EntityForm::save

File

src/Form/AssetInjectorFormBase.php, line 347

Class

AssetInjectorFormBase
Class AssetInjectorCsssForm.

Namespace

Drupal\asset_injector\Form

Code

public function save(array $form, FormStateInterface $form_state) {
  $entity = $this->entity;
  $status = $entity
    ->save();
  switch ($status) {
    case SAVED_NEW:
      $message = $this
        ->t('Created the %label Asset Injector.', [
        '%label' => $entity
          ->label(),
      ]);
      $log = '%type asset %id created';
      break;
    default:
      $message = $this
        ->t('Saved the %label Asset Injector.', [
        '%label' => $entity
          ->label(),
      ]);
      $log = '%type asset %id saved';
  }
  $this
    ->messenger()
    ->addMessage($message);
  $this->logger
    ->notice($log, [
    '%type' => $entity
      ->getEntityTypeId(),
    '%id' => $entity
      ->id(),
  ]);
  $trigger = $form_state
    ->getTriggeringElement();
  if (isset($trigger['#name']) && $trigger['#name'] != 'save_continue') {
    $form_state
      ->setRedirectUrl($entity
      ->toUrl('collection'));
  }
  else {
    $form_state
      ->setRedirectUrl($entity
      ->toUrl());
  }
}