You are here

public function WorkbenchAccessByRoleForm::submitForm in Workbench Access 8

Form submission handler.

Parameters

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

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

Overrides FormInterface::submitForm

File

src/Form/WorkbenchAccessByRoleForm.php, line 109

Class

WorkbenchAccessByRoleForm
Configure Workbench Access per role.

Namespace

Drupal\workbench_access\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $roles = $form_state
    ->getValue('roles');
  $existing_roles = $form_state
    ->getValue('existing_roles');
  $id = $form_state
    ->getValue('section_id');
  foreach ($roles as $role_id => $value) {

    // Add role to section.
    if ($value === $role_id) {
      $this->roleSectionStorage
        ->addRole($this->scheme, $role_id, [
        $id,
      ]);
    }
    else {
      $this->roleSectionStorage
        ->removeRole($this->scheme, $role_id, [
        $id,
      ]);
    }
  }
  \Drupal::messenger()
    ->addMessage($this
    ->t('Role assignments updated.'));
}