public function EditTeamMemberForm::submitForm in Apigee Edge 8
Form submission handler.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides FormInterface::submitForm
File
- modules/
apigee_edge_teams/ src/ Form/ EditTeamMemberForm.php, line 110
Class
- EditTeamMemberForm
- Edit team member form.
Namespace
Drupal\apigee_edge_teams\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$logger = $this
->logger('apigee_edge_teams');
$selected_roles = $this
->filterSelectedRoles($form_state
->getValue('team_roles', []));
$new_roles = array_diff($selected_roles, $form['team_roles']['#default_value']);
$removed_roles = array_diff($form['team_roles']['#default_value'], $selected_roles);
$success = TRUE;
try {
if ($new_roles) {
$this->teamMemberRoleStorage
->addTeamRoles($this->developer
->getOwner(), $this->team, $new_roles);
}
if ($removed_roles) {
$this->teamMemberRoleStorage
->removeTeamRoles($this->developer
->getOwner(), $this->team, $removed_roles);
}
} catch (\Exception $exception) {
$success = FALSE;
$context = [
'%developer' => $this->developer
->getEmail(),
'%team_id' => $this->team
->id(),
];
$context += Error::decodeException($exception);
$logger
->error('Failed to modify %developer developer roles in %team_id team. @message %function (line %line of %file). <pre>@backtrace_string</pre>', $context);
}
if ($success) {
$this
->messenger()
->addStatus($this
->t('Changes successfully saved.'));
}
else {
$this
->messenger()
->addWarning($this
->t('There was an error meanwhile saving the changes.'));
}
}