public function RoleDelegationSettingsForm::buildForm in Role Delegation 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/ RoleDelegationSettingsForm.php, line 63
Class
- RoleDelegationSettingsForm
- Configure book settings for this site.
Namespace
Drupal\role_delegation\FormCode
public function buildForm(array $form, FormStateInterface $form_state, AccountInterface $user = NULL) {
if (!$user instanceof AccountInterface) {
return $form;
}
$current_roles = $user
->getRoles(TRUE);
$current_roles = array_combine($current_roles, $current_roles);
$form['account']['role_change'] = [
'#type' => 'checkboxes',
'#title' => $this
->t('Roles'),
'#options' => $this->delegatableRoles
->getAssignableRoles($this->currentUser),
'#default_value' => $current_roles,
'#description' => $this
->t('Change roles assigned to user.'),
];
$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Save'),
];
return $form;
}