class SocialPrivateMessageThreadMemberFormatter in Open Social 8.3
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
- 8.2 modules/social_features/social_private_message/src/Plugin/Field/FieldFormatter/SocialPrivateMessageThreadMemberFormatter.php \Drupal\social_private_message\Plugin\Field\FieldFormatter\SocialPrivateMessageThreadMemberFormatter
- 8.4 modules/social_features/social_private_message/src/Plugin/Field/FieldFormatter/SocialPrivateMessageThreadMemberFormatter.php \Drupal\social_private_message\Plugin\Field\FieldFormatter\SocialPrivateMessageThreadMemberFormatter
- 8.5 modules/social_features/social_private_message/src/Plugin/Field/FieldFormatter/SocialPrivateMessageThreadMemberFormatter.php \Drupal\social_private_message\Plugin\Field\FieldFormatter\SocialPrivateMessageThreadMemberFormatter
- 8.6 modules/social_features/social_private_message/src/Plugin/Field/FieldFormatter/SocialPrivateMessageThreadMemberFormatter.php \Drupal\social_private_message\Plugin\Field\FieldFormatter\SocialPrivateMessageThreadMemberFormatter
- 8.7 modules/social_features/social_private_message/src/Plugin/Field/FieldFormatter/SocialPrivateMessageThreadMemberFormatter.php \Drupal\social_private_message\Plugin\Field\FieldFormatter\SocialPrivateMessageThreadMemberFormatter
- 8.8 modules/social_features/social_private_message/src/Plugin/Field/FieldFormatter/SocialPrivateMessageThreadMemberFormatter.php \Drupal\social_private_message\Plugin\Field\FieldFormatter\SocialPrivateMessageThreadMemberFormatter
- 10.3.x modules/social_features/social_private_message/src/Plugin/Field/FieldFormatter/SocialPrivateMessageThreadMemberFormatter.php \Drupal\social_private_message\Plugin\Field\FieldFormatter\SocialPrivateMessageThreadMemberFormatter
- 10.0.x modules/social_features/social_private_message/src/Plugin/Field/FieldFormatter/SocialPrivateMessageThreadMemberFormatter.php \Drupal\social_private_message\Plugin\Field\FieldFormatter\SocialPrivateMessageThreadMemberFormatter
- 10.1.x modules/social_features/social_private_message/src/Plugin/Field/FieldFormatter/SocialPrivateMessageThreadMemberFormatter.php \Drupal\social_private_message\Plugin\Field\FieldFormatter\SocialPrivateMessageThreadMemberFormatter
- 10.2.x modules/social_features/social_private_message/src/Plugin/Field/FieldFormatter/SocialPrivateMessageThreadMemberFormatter.php \Drupal\social_private_message\Plugin\Field\FieldFormatter\SocialPrivateMessageThreadMemberFormatter
Defines the private message member field formatter.
Plugin annotation
@FieldFormatter(
id = "social_private_message_thread_member_formatter",
label = @Translation("Social Private Message Thread Members"),
field_types = {
"entity_reference"
},
)
Hierarchy
- class \Drupal\social_private_message\Plugin\Field\FieldFormatter\SocialPrivateMessageThreadMemberFormatter extends \Drupal\private_message\Plugin\Field\FieldFormatter\PrivateMessageThreadMemberFormatter
Expanded class hierarchy of SocialPrivateMessageThreadMemberFormatter
File
- modules/
social_features/ social_private_message/ src/ Plugin/ Field/ FieldFormatter/ SocialPrivateMessageThreadMemberFormatter.php, line 21
Namespace
Drupal\social_private_message\Plugin\Field\FieldFormatterView source
class SocialPrivateMessageThreadMemberFormatter extends PrivateMessageThreadMemberFormatter {
/**
* {@inheritdoc}
*/
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),
];
}
}