You are here

public function WorkflowAccessRoleForm::submitForm in Workflow 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 ConfigFormBase::submitForm

File

modules/workflow_access/src/Form/WorkflowAccessRoleForm.php, line 120

Class

WorkflowAccessRoleForm
Provides the base form for workflow add and edit forms.

Namespace

Drupal\workflow_access\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  foreach ($form_state
    ->getValue($this->entitiesKey) as $sid => $access) {

    // @todo Not waterproof; can be done smarter, using elementchildren().
    if (!WorkflowState::load($sid)) {
      continue;
    }
    foreach ($access['view'] as $rid => $checked) {
      $data[$rid] = [
        'grant_view' => !empty($access['view'][$rid]) ? (bool) $access['view'][$rid] : 0,
        'grant_update' => !empty($access['update'][$rid]) ? (bool) $access['update'][$rid] : 0,
        'grant_delete' => !empty($access['delete'][$rid]) ? (bool) $access['delete'][$rid] : 0,
      ];
    }
    workflow_access_insert_workflow_access_by_sid($sid, $data);

    // Update all nodes to reflect new settings.
    node_access_needs_rebuild(TRUE);
  }
  parent::submitForm($form, $form_state);
}