public function TeamMembersList::overview in Apigee Edge 8
Returns a list of team members.
Parameters
\Drupal\apigee_edge_teams\Entity\TeamInterface $team: The team which members gets listed.
Return value
array Render array.
See also
\Drupal\apigee_edge_teams\Entity\TeamRouteProvider::getListTeamMembersRoute()
File
- modules/
apigee_edge_teams/ src/ Controller/ TeamMembersList.php, line 110
Class
- TeamMembersList
- Team members list builder for a team.
Namespace
Drupal\apigee_edge_teams\ControllerCode
public function overview(TeamInterface $team) {
$entity_type = $this
->entityTypeManager()
->getDefinition('team');
$members = $this->teamMembershipManager
->getMembers($team
->id());
$users_by_mail = [];
$team_member_roles_by_mail = [];
if (!empty($members)) {
$user_storage = $this
->entityTypeManager()
->getStorage('user');
$uids = $user_storage
->getQuery()
->condition('mail', $members, 'IN')
->execute();
$users_by_mail = array_reduce($user_storage
->loadMultiple($uids), function ($carry, UserInterface $item) {
$carry[$item
->getEmail()] = $item;
return $carry;
}, []);
/** @var \Drupal\apigee_edge_teams\Entity\Storage\TeamMemberRoleStorageInterface $team_member_role_storage */
$team_member_role_storage = $this
->entityTypeManager()
->getStorage('team_member_role');
$team_member_roles_by_mail = array_reduce($team_member_role_storage
->loadByTeam($team), function ($carry, TeamMemberRoleInterface $developer_role) {
$carry[$developer_role
->getDeveloper()
->getEmail()] = $developer_role;
return $carry;
}, []);
}
$build['table'] = [
'#type' => 'table',
'#header' => [
'member' => $this
->t('Member'),
'roles' => $this
->t('Roles'),
'operations' => $this
->t('Operations'),
],
'#title' => $this
->t('@team Members', [
'@team' => $entity_type
->getSingularLabel(),
]),
'#rows' => [],
'#empty' => $this
->t('There are no members yet.'),
'#cache' => [
'contexts' => $team
->getCacheContexts(),
'tags' => $team
->getCacheTags(),
],
];
// The list is ordered in the same order as the API returns the members.
foreach ($members as $member) {
$build['table']['#rows'][$member] = $this
->buildRow($member, $users_by_mail, $team_member_roles_by_mail, $team);
}
// Add invitations.
if ($invitation_view = Views::getView('team_invitations')) {
$build['invitations'] = $invitation_view
->buildRenderable('team', [
'team' => $team
->id(),
]);
}
return $build;
}