class RemoveTeamMemberForm in Apigee Edge 8
Remove team members from.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\Core\Form\ConfirmFormBase implements ConfirmFormInterface
- class \Drupal\apigee_edge_teams\Form\RemoveTeamMemberForm
- class \Drupal\Core\Form\ConfirmFormBase implements ConfirmFormInterface
Expanded class hierarchy of RemoveTeamMemberForm
1 file declares its use of RemoveTeamMemberForm
- TeamRouteProvider.php in modules/
apigee_edge_teams/ src/ Entity/ TeamRouteProvider.php
File
- modules/
apigee_edge_teams/ src/ Form/ RemoveTeamMemberForm.php, line 35
Namespace
Drupal\apigee_edge_teams\FormView source
class RemoveTeamMemberForm extends ConfirmFormBase {
/**
* The team from the route.
*
* @var \Drupal\apigee_edge_teams\Entity\TeamInterface
*/
protected $team;
/**
* The developer from the route.
*
* @var \Drupal\apigee_edge\Entity\DeveloperInterface
*/
protected $developer;
/**
* The team entity type definition.
*
* @var \Drupal\Core\Entity\EntityTypeInterface
*/
protected $teamEntityType;
/**
* The team membership manager service.
*
* @var \Drupal\apigee_edge_teams\TeamMembershipManagerInterface
*/
protected $teamMembershipManager;
/**
* The user storage.
*
* @var \Drupal\user\UserStorageInterface
*/
protected $userStorage;
/**
* RemoveTeamMemberForm constructor.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager service.
* @param \Drupal\apigee_edge_teams\TeamMembershipManagerInterface $team_membership_manager
* The team membership manager service.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, TeamMembershipManagerInterface $team_membership_manager) {
$this->teamEntityType = $entity_type_manager
->getDefinition('team');
$this->userStorage = $entity_type_manager
->getStorage('user');
$this->teamMembershipManager = $team_membership_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('entity_type.manager'), $container
->get('apigee_edge_teams.team_membership_manager'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'apigee_edge_teams_remove_team_member_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, TeamInterface $team = NULL, DeveloperInterface $developer = NULL) {
$this->team = $team;
$this->developer = $developer;
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function getQuestion() {
return $this
->t('Are you sure that you would like to remove %developer from the @team?', [
'%developer' => $this
->getDeveloperLabel(),
'@team' => mb_strtolower($this->teamEntityType
->getSingularLabel()),
]);
}
/**
* {@inheritdoc}
*/
public function getCancelUrl() {
return $this->team
->toUrl('members');
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
if (!in_array($this->developer
->getEmail(), $this->teamMembershipManager
->getMembers($this->team
->id()))) {
$form_state
->setError($form, $this
->t('%developer developer is not member of the %team_name @team.', [
'%developer' => $this->developer
->label(),
'%team_name' => $this->team
->getDisplayName(),
'@team' => mb_strtolower($this->teamEntityType
->getSingularLabel()),
]));
$form_state
->setRedirectUrl($this
->getCancelUrl());
}
parent::validateForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$context = [
'%developer' => $this
->getDeveloperLabel(),
'%developer_mail' => $this->developer
->getEmail(),
'@team' => mb_strtolower($this->teamEntityType
->getSingularLabel()),
'%team_id' => $this->team
->id(),
];
$success = FALSE;
try {
$this->teamMembershipManager
->removeMembers($this->team
->id(), [
$this->developer
->getEmail(),
]);
$success = TRUE;
} catch (\Exception $exception) {
$context += Error::decodeException($exception);
$this
->messenger()
->addError($this
->t('Failed to remove %developer developer from the @team. Please try again.', $context));
$this
->logger('apigee_edge_teams')
->error('Failed to remove %developer_mail developer from %team_id @team. @message %function (line %line of %file). <pre>@backtrace_string</pre>', $context);
}
if ($success) {
$this
->messenger()
->addStatus($this
->t('%developer successfully removed from the @team.', $context));
}
}
/**
* Returns the label for a developer.
*
* @return string
* The label for a developer.
*/
protected function getDeveloperLabel() {
$developer_label = $this->developer
->getEmail();
// The developer that we would like to remove from the team may not have
// a Drupal user yet (the two system is out of sync). To resolve this
// possible problem we always try to display the label of the user first
// and we fallback to the developer's email if necessary. We only display
// the email here because this is what a user could see on the team member
// list as well.
// @see \Drupal\apigee_edge_teams\Controller\TeamMembersList::buildRow()
$users = $this->userStorage
->loadByProperties([
'mail' => $this->developer
->getEmail(),
]);
if (!empty($users)) {
/** @var \Drupal\user\UserInterface $user */
$user = reset($users);
$developer_label = $user
->label();
}
return $developer_label;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfirmFormBase:: |
public | function |
Returns a caption for the link which cancels the action. Overrides ConfirmFormInterface:: |
1 |
ConfirmFormBase:: |
public | function |
Returns a caption for the button that confirms the action. Overrides ConfirmFormInterface:: |
20 |
ConfirmFormBase:: |
public | function |
Returns additional text to display as a description. Overrides ConfirmFormInterface:: |
11 |
ConfirmFormBase:: |
public | function |
Returns the internal name used to refer to the confirmation item. Overrides ConfirmFormInterface:: |
|
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 | |
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. | |
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. | |
RemoveTeamMemberForm:: |
protected | property | The developer from the route. | |
RemoveTeamMemberForm:: |
protected | property | The team from the route. | |
RemoveTeamMemberForm:: |
protected | property | The team entity type definition. | |
RemoveTeamMemberForm:: |
protected | property | The team membership manager service. | |
RemoveTeamMemberForm:: |
protected | property | The user storage. | |
RemoveTeamMemberForm:: |
public | function |
Form constructor. Overrides ConfirmFormBase:: |
|
RemoveTeamMemberForm:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
|
RemoveTeamMemberForm:: |
public | function |
Returns the route to go to if the user cancels the action. Overrides ConfirmFormInterface:: |
|
RemoveTeamMemberForm:: |
protected | function | Returns the label for a developer. | |
RemoveTeamMemberForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
RemoveTeamMemberForm:: |
public | function |
Returns the question to ask the user. Overrides ConfirmFormInterface:: |
|
RemoveTeamMemberForm:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
RemoveTeamMemberForm:: |
public | function |
Form validation handler. Overrides FormBase:: |
|
RemoveTeamMemberForm:: |
public | function | RemoveTeamMemberForm constructor. | |
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. | |
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. |