You are here

function photos_theme_photos_comment_count in Album Photos 8.4

Same name and namespace in other branches
  1. 8.5 photos.module \photos_theme_photos_comment_count()
  2. 7.3 photos.module \photos_theme_photos_comment_count()

Theme photos comment count.

1 string reference to 'photos_theme_photos_comment_count'
photos_theme in ./photos.module
Implements hook_theme().

File

./photos.module, line 1425
Implementation of photos.module.

Code

function photos_theme_photos_comment_count($variables) {
  $url = $variables['url'];
  $comcount = $variables['comcount'];
  $comment = '';
  if (\Drupal::moduleHandler()
    ->moduleExists('comment')) {

    // @todo also check if comments are enabled for photos content type.
    if (empty($comcount)) {
      if (!\Drupal::currentUser()
        ->hasPermission('post comments')) {
        $comment = t('<a href="@login">Login</a> to post comments', [
          '@login' => Url::fromRoute('user.login')
            ->toString(),
        ]);
      }
      else {
        $comment = '<a href="' . (isset($url) ? $url . '#comment-form' : '#comment-form') . '">' . t('Add new comment') . '</a>';
      }
    }
    else {
      $comment_count = \Drupal::translation()
        ->formatPlural($comcount, '1 comment', '@count comments');
      $comment = '<a href="' . (isset($url) ? $url . '#comments' : '#comments') . '">' . $comment_count . '</a>';
    }
  }
  return $comment;
}