public function RoleFormController::save

Form submission handler for the 'save' action.

Parameters

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

array $form_state: A reference to a keyed array containing the current state of the form.

Overrides EntityFormController::save

File

drupal/core/modules/user/lib/Drupal/user/RoleFormController.php, line 64
Contains \Drupal\user\RoleFormController.

Class

RoleFormController
Form controller for the role entity edit forms.

Namespace

Drupal\user

Code

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

  // Prevent leading and trailing spaces in role names.
  $entity
    ->set('label', trim($entity
    ->label()));
  $uri = $entity
    ->uri();
  if ($entity
    ->save() == SAVED_UPDATED) {
    drupal_set_message(t('Role %label has been updated.', array(
      '%label' => $entity
        ->label(),
    )));
    watchdog('user', 'Role %label has been updated.', array(
      '%label' => $entity
        ->label(),
    ), WATCHDOG_NOTICE, l(t('Edit'), $uri['path']));
  }
  else {
    drupal_set_message(t('Role %label has been added.', array(
      '%label' => $entity
        ->label(),
    )));
    watchdog('user', 'Role %label has been added.', array(
      '%label' => $entity
        ->label(),
    ), WATCHDOG_NOTICE, l(t('Edit'), $uri['path']));
  }
  $form_state['redirect'] = 'admin/people/roles';
}