You are here

function social_mentions_comment_links_alter in Open Social 8.3

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_mentions/social_mentions.module \social_mentions_comment_links_alter()
  2. 8 modules/social_features/social_mentions/social_mentions.module \social_mentions_comment_links_alter()
  3. 8.2 modules/social_features/social_mentions/social_mentions.module \social_mentions_comment_links_alter()
  4. 8.4 modules/social_features/social_mentions/social_mentions.module \social_mentions_comment_links_alter()
  5. 8.5 modules/social_features/social_mentions/social_mentions.module \social_mentions_comment_links_alter()
  6. 8.6 modules/social_features/social_mentions/social_mentions.module \social_mentions_comment_links_alter()
  7. 8.7 modules/social_features/social_mentions/social_mentions.module \social_mentions_comment_links_alter()
  8. 8.8 modules/social_features/social_mentions/social_mentions.module \social_mentions_comment_links_alter()
  9. 10.3.x modules/social_features/social_mentions/social_mentions.module \social_mentions_comment_links_alter()
  10. 10.0.x modules/social_features/social_mentions/social_mentions.module \social_mentions_comment_links_alter()
  11. 10.1.x modules/social_features/social_mentions/social_mentions.module \social_mentions_comment_links_alter()
  12. 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 101
Contains social_mentions.module.

Code

function social_mentions_comment_links_alter(array &$links, CommentInterface $entity, array &$context) {
  $field_name = $entity
    ->getFieldName();
  $commented_entity = $entity
    ->getCommentedEntity();
  if ($entity
    ->hasParentComment() && $commented_entity
    ->get($field_name)->status == CommentItemInterface::OPEN) {

    /* @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_PROFILE_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_PROFILE_SUGGESTIONS_FULL_NAME && $account
      ->getAccountName() == $account
      ->getDisplayName()) {
      return;
    }
    $links['comment']['#links']['comment-reply'] = [
      'title' => t('Reply'),
    ];

    // If the comment is not published disable the reply link.
    if ($entity
      ->isPublished()) {
      $links['comment']['#links']['comment-reply']['url'] = Url::fromUserInput('#' . $entity
        ->getParentComment()
        ->id());
      $links['comment']['#links']['comment-reply']['attributes'] = [
        'class' => [
          'mention-reply',
        ],
        'data-author' => Json::encode($item),
      ];
    }
    else {
      $links['comment']['#links']['comment-reply']['url'] = Url::fromRoute('<nolink>');
    }
  }
}