public function AssignUserForm::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/ AssignUserForm.php, line 192
Class
- AssignUserForm
- Builds the workbench_access set switch form.
Namespace
Drupal\workbench_access\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$values = $form_state
->getValues();
$items = [];
foreach ($values['schemes'] as $id) {
$items[$id]['scheme'] = $values['scheme_' . $id];
$items[$id]['selections'] = $values['active_' . $id];
}
foreach ($items as $item) {
// Add sections.
$sections = array_filter($item['selections'], function ($val) {
return !empty($val);
});
$sections = array_keys($sections);
$this->userSectionStorage
->addUser($item['scheme'], $this->user, $sections);
// Remove sections.
$remove_sections = array_keys(array_filter($item['selections'], function ($val) {
return empty($val);
}));
$this->userSectionStorage
->removeUser($item['scheme'], $this->user, $remove_sections);
}
}