public function WorkbenchAccessByRoleForm::buildForm in Workbench Access 8
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
- src/
Form/ WorkbenchAccessByRoleForm.php, line 71
Class
- WorkbenchAccessByRoleForm
- Configure Workbench Access per role.
Namespace
Drupal\workbench_access\FormCode
public function buildForm(array $form, FormStateInterface $form_state, AccessSchemeInterface $access_scheme = NULL, $id = NULL) {
$this->scheme = $access_scheme;
$existing_roles = $this->roleSectionStorage
->getRoles($access_scheme, $id);
$potential_roles = $this->roleSectionStorage
->getPotentialRolesFiltered($id);
$form['existing_roles'] = [
'#type' => 'value',
'#value' => $existing_roles,
];
$form['section_id'] = [
'#type' => 'value',
'#value' => $id,
];
if (!$existing_roles) {
$text = $this
->t('There are no roles assigned to the %label section.', [
'%label' => $access_scheme
->label(),
]);
$form['help'] = [
'#type' => 'markup',
'#markup' => '<p>' . $text . '</p>',
];
}
if ($potential_roles) {
$form['roles'] = [
'#title' => $this
->t('Roles for the %label section.', [
'%label' => $access_scheme
->label(),
]),
'#type' => 'checkboxes',
'#options' => $potential_roles,
'#default_value' => $existing_roles,
];
$form['actions'] = [
'#type' => 'actions',
];
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Submit'),
];
}
if (count($potential_roles) == count($existing_roles)) {
$form['message'] = [
'#type' => 'markup',
'#markup' => '<p>' . $this
->t('There are no additional roles that can be added to the %label section', [
'%label' => $access_scheme
->label(),
]) . '</p>',
];
}
return $form;
}