You are here

function olivero_preprocess_field__comment in Drupal 9

Implements hook_preprocess_HOOK() for field--comment.html.twig.

File

core/themes/olivero/olivero.theme, line 550
Functions to support theming in the Olivero theme.

Code

function olivero_preprocess_field__comment(&$variables) {

  // Add a comment_count.
  $variables['comment_count'] = count(array_filter($variables['comments'], 'is_numeric', ARRAY_FILTER_USE_KEY));

  // Add user.compact to field-comment if profile's avatar of current user
  // exist.
  $user = \Drupal::currentUser();
  if ($user
    ->isAuthenticated() && $user instanceof UserInterface) {
    if ($user
      ->hasField('user_picture') && !$user
      ->get('user_picture')
      ->isEmpty()) {
      $variables['user_picture'] = \Drupal::entityTypeManager()
        ->getViewBuilder('user')
        ->view($user, 'compact');
    }
    $variables['#cache']['contexts'][] = 'user';
  }
}