public function ConfigPermListForm::submitForm in Custom Permissions 8.2
Same name and namespace in other branches
- 8 src/Form/ConfigPermListForm.php \Drupal\config_perms\Form\ConfigPermListForm::submitForm()
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/ ConfigPermListForm.php, line 231
Class
- ConfigPermListForm
- Class ConfigPermListForm.
Namespace
Drupal\config_perms\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$values = $form_state
->getValues();
$perms = CustomPermsEntity::loadMultiple();
foreach ($values['local'] as $key => $data) {
// If new permission.
if ($key == 'new') {
$entity = CustomPermsEntity::create();
$entity
->set('id', $this
->configPermsGenerateMachineName($data['name']));
}
else {
// Update || Insert.
$entity = $perms[$data['id']];
}
$entity
->set('label', $data['name']);
$entity
->set('route', $data['route']);
$entity
->set('status', $data['status']);
$entity
->save();
}
$this->routerBuilder
->rebuild();
$this
->messenger()
->addMessage($this
->t('The permissions have been saved.'));
}