public function RoleAccessControlRelationsForm::buildForm in Role Access Control 8.2
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides FormInterface::buildForm
File
- modules/
rac_relations/ src/ Form/ RoleAccessControlRelationsForm.php, line 23
Class
- RoleAccessControlRelationsForm
- Contribute form.
Namespace
Drupal\rac_relations\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$roles = user_roles();
$form['table_title'] = [
'#type' => 'item',
'#title' => $this
->t('Update Grants'),
'#description' => $this
->t('For each row, configure which roles (columns) for which editing is approved.'),
];
$form['role_access'] = [
'#type' => 'table',
'#header' => [
'',
],
'#id' => 'role-access-all',
'#attributes' => [
'class' => [
'role-access-all',
'js-role-access-all',
],
],
'#sticky' => TRUE,
];
foreach ($roles as $role) {
$form['role_access']['#header'][] = [
'data' => $role
->label(),
'class' => [
'checkbox',
],
];
}
foreach ($roles as $rid => $role) {
// Fill in default values for the permission.
$form['role_access'][$rid]['description'] = [
'#type' => 'inline_template',
'#template' => '<div class=\'permission\'><span class=\'title\'>{{ title }}</span></div>',
'#context' => [
'title' => $role
->label(),
],
];
foreach ($roles as $srid => $srole) {
$permission = 'RAC update ' . $srole
->id();
$form['role_access'][$rid][$srid] = [
'#title' => $role
->label() . ' can edit for ' . $srole
->label(),
'#title_display' => 'invisible',
'#wrapper_attributes' => [
'class' => [
'checkbox',
],
],
'#type' => 'checkbox',
'#default_value' => 0,
'#attributes' => [
'class' => [
'rid-' . $srid,
'js-rid-' . $srid,
],
],
'#parents' => [
$rid,
$srid,
],
];
if ($role
->isAdmin()) {
$form['role_access'][$rid][$srid]['#disabled'] = TRUE;
}
if ($role
->hasPermission($permission)) {
$form['role_access'][$rid][$srid]['#default_value'] = 1;
}
}
}
$form['actions'] = [
'#type' => 'actions',
];
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Save permissions'),
'#button_type' => 'primary',
];
return $form;
}