public function SocialPrivateMessageThreadMemberFormatter::viewElements in Open Social 8.6
Same name and namespace in other branches
- 8.9 modules/social_features/social_private_message/src/Plugin/Field/FieldFormatter/SocialPrivateMessageThreadMemberFormatter.php \Drupal\social_private_message\Plugin\Field\FieldFormatter\SocialPrivateMessageThreadMemberFormatter::viewElements()
- 8.2 modules/social_features/social_private_message/src/Plugin/Field/FieldFormatter/SocialPrivateMessageThreadMemberFormatter.php \Drupal\social_private_message\Plugin\Field\FieldFormatter\SocialPrivateMessageThreadMemberFormatter::viewElements()
- 8.3 modules/social_features/social_private_message/src/Plugin/Field/FieldFormatter/SocialPrivateMessageThreadMemberFormatter.php \Drupal\social_private_message\Plugin\Field\FieldFormatter\SocialPrivateMessageThreadMemberFormatter::viewElements()
- 8.4 modules/social_features/social_private_message/src/Plugin/Field/FieldFormatter/SocialPrivateMessageThreadMemberFormatter.php \Drupal\social_private_message\Plugin\Field\FieldFormatter\SocialPrivateMessageThreadMemberFormatter::viewElements()
- 8.5 modules/social_features/social_private_message/src/Plugin/Field/FieldFormatter/SocialPrivateMessageThreadMemberFormatter.php \Drupal\social_private_message\Plugin\Field\FieldFormatter\SocialPrivateMessageThreadMemberFormatter::viewElements()
- 8.7 modules/social_features/social_private_message/src/Plugin/Field/FieldFormatter/SocialPrivateMessageThreadMemberFormatter.php \Drupal\social_private_message\Plugin\Field\FieldFormatter\SocialPrivateMessageThreadMemberFormatter::viewElements()
- 8.8 modules/social_features/social_private_message/src/Plugin/Field/FieldFormatter/SocialPrivateMessageThreadMemberFormatter.php \Drupal\social_private_message\Plugin\Field\FieldFormatter\SocialPrivateMessageThreadMemberFormatter::viewElements()
- 10.3.x modules/social_features/social_private_message/src/Plugin/Field/FieldFormatter/SocialPrivateMessageThreadMemberFormatter.php \Drupal\social_private_message\Plugin\Field\FieldFormatter\SocialPrivateMessageThreadMemberFormatter::viewElements()
- 10.0.x modules/social_features/social_private_message/src/Plugin/Field/FieldFormatter/SocialPrivateMessageThreadMemberFormatter.php \Drupal\social_private_message\Plugin\Field\FieldFormatter\SocialPrivateMessageThreadMemberFormatter::viewElements()
- 10.1.x modules/social_features/social_private_message/src/Plugin/Field/FieldFormatter/SocialPrivateMessageThreadMemberFormatter.php \Drupal\social_private_message\Plugin\Field\FieldFormatter\SocialPrivateMessageThreadMemberFormatter::viewElements()
- 10.2.x modules/social_features/social_private_message/src/Plugin/Field/FieldFormatter/SocialPrivateMessageThreadMemberFormatter.php \Drupal\social_private_message\Plugin\Field\FieldFormatter\SocialPrivateMessageThreadMemberFormatter::viewElements()
File
- modules/
social_features/ social_private_message/ src/ Plugin/ Field/ FieldFormatter/ SocialPrivateMessageThreadMemberFormatter.php, line 26
Class
- SocialPrivateMessageThreadMemberFormatter
- Defines the private message member field formatter.
Namespace
Drupal\social_private_message\Plugin\Field\FieldFormatterCode
public function viewElements(FieldItemListInterface $items, $langcode) {
$access_profiles = $this->currentUser
->hasPermission('access user profiles');
$users = [];
$view_builder = $this->entityManager
->getViewBuilder('user');
foreach ($items as $delta => $item) {
/** @var \Drupal\user\UserInterface $user */
$user = $item->entity;
if ($user) {
if ($this
->getSetting('display_type') == 'label') {
if ($access_profiles) {
$url = Url::fromRoute('entity.user.canonical', [
'user' => $user
->id(),
]);
$users[$user
->id()] = new FormattableMarkup('<a href=":link">@username</a>', [
':link' => $url
->toString(),
'@username' => $user
->getDisplayName(),
]);
}
else {
$users[$user
->id()] = $user
->getDisplayName();
}
}
elseif ($this
->getSetting('display_type') == 'entity') {
$renderable = $view_builder
->view($user, $this
->getSetting('entity_display_mode'));
$users[$user
->id()] = render($renderable);
}
}
else {
$users['Missing-' . $delta] = $this
->t('Deleted user');
}
}
$separator = $this
->getSetting('display_type') == 'label' ? ', ' : '';
return [
'#type' => 'html_tag',
'#tag' => 'div',
'#attributes' => [
'class' => [
'message__thread-members',
],
],
'#value' => implode($separator, $users),
];
}