You are here

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

Class

EditTeamMemberForm
Edit team member form.

Namespace

Drupal\apigee_edge_teams\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, TeamInterface $team = NULL, DeveloperInterface $developer = NULL) {
  $this->team = $team;
  $this->developer = $developer;
  $role_options = $this
    ->getRoleOptions();
  $team_member_roles = $this->teamMemberRoleStorage
    ->loadByDeveloperAndTeam($developer
    ->getOwner(), $team);
  if ($team_member_roles) {
    $current_role_options = array_keys($team_member_roles
      ->getTeamRoles());
  }
  else {
    $current_role_options = [];
  }

  // Add TEAM_MEMBER_ROLE to current role options so it's always displayed.
  $current_role_options[] = TeamRoleInterface::TEAM_MEMBER_ROLE;
  $form['team_roles'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Roles'),
    '#options' => $role_options,
    '#default_value' => $current_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('Modify roles of %developer in the %team_label @team.', [
      '%developer' => $this->developer
        ->getOwner()
        ->label(),
      '%team_label' => $this->team
        ->label(),
      '@team' => mb_strtolower($this->team
        ->getEntityType()
        ->getSingularLabel()),
    ]),
  ];
  $form['actions'] = [
    '#type' => 'actions',
    'submit' => [
      '#type' => 'submit',
      '#value' => $this
        ->t('Save'),
      '#button_type' => 'primary',
    ],
    'cancel' => [
      '#type' => 'link',
      '#title' => $this
        ->t('Cancel'),
      '#attributes' => [
        'class' => [
          'button',
        ],
      ],
      '#url' => $this->team
        ->toUrl('members'),
    ],
  ];
  return $form;
}