protected function PfmUserPermissionsForm::fillPermissionTable in Permissions filtered by modules 8
Helper method for filling Permission Table.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
array $table_build_info: The current table build information.
1 call to PfmUserPermissionsForm::fillPermissionTable()
- PfmUserPermissionsForm::buildForm in src/
Form/ PfmUserPermissionsForm.php - Form constructor.
File
- src/
Form/ PfmUserPermissionsForm.php, line 170
Class
- PfmUserPermissionsForm
- Provides the user permissions administration PFM module form.
Namespace
Drupal\pfm\FormCode
protected function fillPermissionTable(array &$form, FormStateInterface &$form_state, array $table_build_info) {
list($permissions_by_provider, $role_names, $role_permissions, $admin_roles, $selected_modules, $selected_roles, ) = $table_build_info;
foreach ($permissions_by_provider as $provider => $permissions) {
// Module name.
if (!in_array($provider, $selected_modules)) {
continue;
}
$form['permissions'][$provider] = [
[
'#wrapper_attributes' => [
'colspan' => count($role_names) + 1,
'class' => [
'module',
],
'id' => 'module-' . $provider,
],
'#markup' => $this->moduleHandler
->getName($provider),
],
];
foreach ($permissions as $perm => $perm_item) {
// Fill in default values for the permission.
$perm_item += [
'description' => '',
'restrict access' => FALSE,
'warning' => !empty($perm_item['restrict access']) ? $this
->t('Warning: Give to trusted roles only; this permission has security implications.') : '',
];
$form['permissions'][$perm]['description'] = [
'#type' => 'inline_template',
'#template' => '<div class="permission"><span class="title">{{ title }}</span>{% if description or warning %}<div class="description">{% if warning %}<em class="permission-warning">{{ warning }}</em> {% endif %}{{ description }}</div>{% endif %}</div>',
'#context' => [
'title' => $perm_item['title'],
],
];
$form['permissions'][$perm]['description']['#context']['description'] = $perm_item['description'];
$form['permissions'][$perm]['description']['#context']['warning'] = $perm_item['warning'];
foreach ($role_names as $rid => $name) {
if (in_array('all', $selected_roles) || in_array($rid, $selected_roles)) {
$checked = in_array($perm, $role_permissions[$rid]) ? TRUE : FALSE;
$form['permissions'][$perm][$rid] = [
'#title' => $name . ': ' . $perm_item['title'],
'#title_display' => 'invisible',
'#wrapper_attributes' => [
'class' => [
'checkbox',
],
],
'#type' => 'checkbox',
'#default_value' => $checked,
'#attributes' => [
'class' => [
'rid-' . $rid,
'js-rid-' . $rid,
],
'checked' => $checked,
],
'#parents' => [
$rid,
$perm,
],
];
// Show a column of disabled but checked checkboxes.
if ($admin_roles[$rid]) {
$form['permissions'][$perm][$rid]['#disabled'] = TRUE;
$form['permissions'][$perm][$rid]['#default_value'] = TRUE;
}
}
}
}
}
}