You are here

public function DirectoryForm::save in Private files download permission 8.2

Same name and namespace in other branches
  1. 3.x src/Form/DirectoryForm.php \Drupal\pfdp\Form\DirectoryForm::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/DirectoryForm.php, line 110

Class

DirectoryForm
Directory form for private_files_download_permission.

Namespace

Drupal\pfdp\Form

Code

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

  // Save the directory and display the status message.
  try {
    $pfdp_directory
      ->save();
    $this
      ->logger('pfdp')
      ->info('The directory %path was saved successfully.', [
      '%path' => $pfdp_directory->path,
    ]);
    \Drupal::messenger()
      ->addStatus($this
      ->t('The directory %path was saved successfully.', [
      '%path' => $pfdp_directory->path,
    ]));
  } catch (EntityStorageException $exception) {
    $this
      ->logger('pfdp')
      ->error('The directory %path was not saved.', [
      '%path' => $pfdp_directory->path,
    ]);
    \Drupal::messenger()
      ->addError($this
      ->t('The directory %path was not saved.', [
      '%path' => $pfdp_directory->path,
    ]));
  }

  // Redirect to the proper url.
  $form_state
    ->setRedirect('entity.pfdp_directory');
}