function social_mentions_comment_links_alter in Open Social 8
Same name and namespace in other branches
- 8.9 modules/social_features/social_mentions/social_mentions.module \social_mentions_comment_links_alter()
- 8.2 modules/social_features/social_mentions/social_mentions.module \social_mentions_comment_links_alter()
- 8.3 modules/social_features/social_mentions/social_mentions.module \social_mentions_comment_links_alter()
- 8.4 modules/social_features/social_mentions/social_mentions.module \social_mentions_comment_links_alter()
- 8.5 modules/social_features/social_mentions/social_mentions.module \social_mentions_comment_links_alter()
- 8.6 modules/social_features/social_mentions/social_mentions.module \social_mentions_comment_links_alter()
- 8.7 modules/social_features/social_mentions/social_mentions.module \social_mentions_comment_links_alter()
- 8.8 modules/social_features/social_mentions/social_mentions.module \social_mentions_comment_links_alter()
- 10.3.x modules/social_features/social_mentions/social_mentions.module \social_mentions_comment_links_alter()
- 10.0.x modules/social_features/social_mentions/social_mentions.module \social_mentions_comment_links_alter()
- 10.1.x modules/social_features/social_mentions/social_mentions.module \social_mentions_comment_links_alter()
- 10.2.x modules/social_features/social_mentions/social_mentions.module \social_mentions_comment_links_alter()
Implements hook_comment_links_alter().
File
- modules/
social_features/ social_mentions/ social_mentions.module, line 100 - Contains social_mentions.module.
Code
function social_mentions_comment_links_alter(array &$links, CommentInterface $entity, array &$context) {
if ($entity
->hasParentComment()) {
/* @var \Drupal\Core\Session\AccountInterface $account */
$account = $entity
->getOwner();
$storage = \Drupal::entityTypeManager()
->getStorage('profile');
$config = \Drupal::config('mentions.settings');
$suggestions_format = $config
->get('suggestions_format');
$item = [
'uid' => $account
->id(),
'username' => $account
->getAccountName(),
'value' => $account
->getAccountName(),
'html_item' => '',
'profile_id' => '',
];
if ($suggestions_format != SOCIAL_MENTIONS_SUGGESTIONS_USERNAME) {
/* @var \Drupal\profile\Entity\ProfileInterface $profile */
if ($storage && ($profile = $storage
->loadByUser($account, 'profile', TRUE))) {
$item['profile_id'] = $profile
->id();
$item['value'] = $account
->getDisplayName();
}
}
// Disable reply if full name is not set for only username format.
if ($suggestions_format == SOCIAL_MENTIONS_SUGGESTIONS_FULL_NAME && $account
->getAccountName() == $account
->getDisplayName()) {
return;
}
$links['comment']['#links']['comment-reply'] = [
'title' => t('Reply'),
'url' => Url::fromUserInput('#' . $entity
->getParentComment()
->id()),
'attributes' => [
'class' => [
'mention-reply',
],
'data-author' => Json::encode($item),
],
];
}
}