class EditTeamMemberForm in Apigee Edge 8
Edit team member form.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\apigee_edge_teams\Form\TeamMembersFormBase
- class \Drupal\apigee_edge_teams\Form\EditTeamMemberForm
- class \Drupal\apigee_edge_teams\Form\TeamMembersFormBase
Expanded class hierarchy of EditTeamMemberForm
1 file declares its use of EditTeamMemberForm
- TeamRouteProvider.php in modules/
apigee_edge_teams/ src/ Entity/ TeamRouteProvider.php
File
- modules/
apigee_edge_teams/ src/ Form/ EditTeamMemberForm.php, line 32
Namespace
Drupal\apigee_edge_teams\FormView source
class EditTeamMemberForm extends TeamMembersFormBase {
/**
* The developer from the route.
*
* @var \Drupal\apigee_edge\Entity\DeveloperInterface
*/
protected $developer;
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'apigee_edge_teams_edit_team_member_form';
}
/**
* {@inheritdoc}
*/
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;
}
/**
* {@inheritdoc}
*/
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.'));
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
EditTeamMemberForm:: |
protected | property | The developer from the route. | |
EditTeamMemberForm:: |
public | function |
Form constructor. Overrides FormInterface:: |
|
EditTeamMemberForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
EditTeamMemberForm:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
FormBase:: |
protected | property | The config factory. | 1 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Retrieves a configuration object. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
FormBase:: |
public | function |
Form validation handler. Overrides FormInterface:: |
62 |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
TeamMembersFormBase:: |
protected | property | The team from the route. | |
TeamMembersFormBase:: |
protected | property | Team member role storage. | |
TeamMembersFormBase:: |
protected | property | Team role storage. | |
TeamMembersFormBase:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
1 |
TeamMembersFormBase:: |
protected | function | Helper function to filter the value of a team roles checkboxes element. | |
TeamMembersFormBase:: |
protected | function | Returns an array of team role options keyed by team role id. | |
TeamMembersFormBase:: |
public | function | TeamMembersFormBase constructor. | 1 |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |