You are here

public function OgAddMultipleRolesForm::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/OgAddMultipleRolesForm.php, line 25

Class

OgAddMultipleRolesForm
Provides a form to add multiple OG roles to a membership.

Namespace

Drupal\og\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $options = [];
  foreach ($this
    ->getGroupTypes() as $group_type) {

    /** @var \Drupal\og\OgRoleInterface $role */
    foreach (OgRole::loadByGroupType($group_type['entity_type_id'], $group_type['bundle_id']) as $role) {

      // Only add the role to the list if it is not a required role, these
      // cannot be added.
      if (!$role
        ->isRequired()) {
        $options[$role
          ->id()] = $role
          ->label();
      }
    }
  }
  $form['roles'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Add roles'),
    '#multiple' => TRUE,
    '#required' => TRUE,
    '#options' => $options,
  ];
  return parent::buildForm($form, $form_state);
}