protected function ContentAccessRoleBasedFormTrait::roleBasedForm in Content Access 8
Builds the role based permission form for the given defaults.
Parameters
array $form: An associative array containing the structure of the form.
array $defaults: Array of defaults for all operations.
string $type: The node type id.
2 calls to ContentAccessRoleBasedFormTrait::roleBasedForm()
- ContentAccessAdminSettingsForm::buildForm in src/
Form/ ContentAccessAdminSettingsForm.php - Form constructor.
- ContentAccessPageForm::buildForm in src/
Form/ ContentAccessPageForm.php - Form constructor.
File
- src/
Form/ ContentAccessRoleBasedFormTrait.php, line 26
Class
- ContentAccessRoleBasedFormTrait
- Common components for Content Access forms.
Namespace
Drupal\content_access\FormCode
protected function roleBasedForm(array &$form, array $defaults = [], $type = NULL) {
$description = [
t('Note that users need at least the %access_content permission to be able to deal in any way with content.', [
'%access_content' => t('access content'),
]),
t('Furthermore note that content which is not published is treated in a different way by Drupal: It can be viewed only by its author or users with the %perm permission.', [
'%perm' => t('bypass node access'),
]),
];
$form['per_role'] = [
'#type' => 'fieldset',
'#title' => t('Role based access control settings'),
'#collapsible' => TRUE,
'#description' => implode(' ', $description),
];
$operations = _content_access_get_operations($type);
$user_roles = Role::loadMultiple();
$roles = [];
foreach ($user_roles as $role) {
$roles[$role
->id()] = $role
->get('label');
}
foreach ($operations as $op => $label) {
// Make sure defaults are set properly.
$defaults += [
$op => [],
];
$form['per_role'][$op] = [
'#type' => 'checkboxes',
'#prefix' => '<div class="content_access-div">',
'#suffix' => '</div>',
'#options' => $roles,
'#title' => $label,
'#default_value' => $defaults[$op],
];
$form['per_role'][$op]['#process'] = [
[
'\\Drupal\\Core\\Render\\Element\\Checkboxes',
'processCheckboxes',
],
[
'\\Drupal\\content_access\\Form\\ContentAccessRoleBasedFormTrait',
'disableCheckboxes',
],
];
}
$form['per_role']['clearer'] = [
'#value' => '<br clear="all" />',
];
$form['#attached']['library'][] = 'content_access/drupal.content_access';
return $form;
}