You are here

public function RoleForm::save in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/user/src/RoleForm.php \Drupal\user\RoleForm::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

core/modules/user/src/RoleForm.php, line 54
Contains \Drupal\user\RoleForm.

Class

RoleForm
Form controller for the role entity edit forms.

Namespace

Drupal\user

Code

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

  // Prevent leading and trailing spaces in role names.
  $entity
    ->set('label', trim($entity
    ->label()));
  $status = $entity
    ->save();
  $edit_link = $this->entity
    ->link($this
    ->t('Edit'));
  if ($status == SAVED_UPDATED) {
    drupal_set_message($this
      ->t('Role %label has been updated.', array(
      '%label' => $entity
        ->label(),
    )));
    $this
      ->logger('user')
      ->notice('Role %label has been updated.', array(
      '%label' => $entity
        ->label(),
      'link' => $edit_link,
    ));
  }
  else {
    drupal_set_message($this
      ->t('Role %label has been added.', array(
      '%label' => $entity
        ->label(),
    )));
    $this
      ->logger('user')
      ->notice('Role %label has been added.', array(
      '%label' => $entity
        ->label(),
      'link' => $edit_link,
    ));
  }
  $form_state
    ->setRedirect('entity.user_role.collection');
}