You are here

public function WebformAccessGroupForm::save in Webform 8.5

Same name and namespace in other branches
  1. 6.x modules/webform_access/src/WebformAccessGroupForm.php \Drupal\webform_access\WebformAccessGroupForm::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

modules/webform_access/src/WebformAccessGroupForm.php, line 366

Class

WebformAccessGroupForm
Provides a form to define a webform access group.

Namespace

Drupal\webform_access

Code

public function save(array $form, FormStateInterface $form_state) {

  /** @var \Drupal\webform_access\WebformAccessGroupInterface $webform_access_group */
  $webform_access_group = $this
    ->getEntity();
  $webform_access_group
    ->setAdminIds($form_state
    ->getValue('admins'));
  $webform_access_group
    ->setUserIds($form_state
    ->getValue('users'));
  $webform_access_group
    ->setEntityIds($form_state
    ->getValue('entities'));
  $webform_access_group
    ->setEmails($form_state
    ->getValue('emails'));
  $webform_access_group
    ->save();

  // Log and display message.
  $context = [
    '@label' => $webform_access_group
      ->label(),
    'link' => $webform_access_group
      ->toLink($this
      ->t('Edit'), 'edit-form')
      ->toString(),
  ];
  $this
    ->logger('webform')
    ->notice('Access group @label saved.', $context);
  $this
    ->messenger()
    ->addStatus($this
    ->t('Access group %label saved.', [
    '%label' => $webform_access_group
      ->label(),
  ]));

  // Redirect to list.
  $form_state
    ->setRedirect('entity.webform_access_group.collection');
}