You are here

public function AddTeamMembersForm::buildForm in Apigee Edge 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

modules/apigee_edge_teams/src/Form/AddTeamMembersForm.php, line 93

Class

AddTeamMembersForm
Add team members form.

Namespace

Drupal\apigee_edge_teams\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, TeamInterface $team = NULL) {
  $this->team = $team;
  $role_options = $this
    ->getRoleOptions();
  $form['developers'] = [
    '#title' => $this
      ->t('Developers'),
    '#description' => $this
      ->t('Enter the email of one or more developers to invite them to the @team, separated by comma.', [
      '@team' => mb_strtolower($this->team
        ->getEntityType()
        ->getSingularLabel()),
    ]),
    '#type' => 'textarea',
    '#required' => TRUE,
  ];
  $form['team_roles'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Roles'),
    '#options' => $role_options,
    '#multiple' => TRUE,
    '#required' => FALSE,
  ];

  // Special handling for the inevitable team member role.
  $form['team_roles'][TeamRoleInterface::TEAM_MEMBER_ROLE] = [
    '#default_value' => TRUE,
    '#disabled' => TRUE,
  ];
  $form['team_roles']['description'] = [
    '#markup' => $this
      ->t('Assign one or more roles to <em>all developers</em> that you selected in %team_label @team.', [
      '%team_label' => $this->team
        ->label(),
      '@team' => mb_strtolower($this->team
        ->getEntityType()
        ->getSingularLabel()),
    ]),
  ];
  $form['actions'] = [
    '#type' => 'actions',
    'submit' => [
      '#type' => 'submit',
      '#value' => $this
        ->t('Invite members'),
      '#button_type' => 'primary',
    ],
    'cancel' => [
      '#type' => 'link',
      '#title' => $this
        ->t('Cancel'),
      '#attributes' => [
        'class' => [
          'button',
        ],
      ],
      '#url' => $this->team
        ->toUrl('members'),
    ],
  ];
  return $form;
}