public function OgRemoveMultipleRolesForm::buildForm in Organic groups 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 OgChangeMultipleRolesFormBase::buildForm
File
- src/
Form/ OgRemoveMultipleRolesForm.php, line 25
Class
- OgRemoveMultipleRolesForm
- Provides a form to remove multiple OG roles from a membership.
Namespace
Drupal\og\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$options = [];
foreach ($this
->getMemberships() as $membership) {
foreach ($membership
->getRoles() as $role) {
// Only add the role to the list if it is not a required role, these
// cannot be removed.
if (!$role
->isRequired()) {
$options[$role
->id()] = $role
->label();
}
}
}
$form['roles'] = [
'#type' => 'select',
'#title' => $this
->t('Remove roles'),
'#multiple' => TRUE,
'#required' => TRUE,
'#options' => $options,
];
return parent::buildForm($form, $form_state);
}