function olivero_preprocess_field__comment

Same name and namespace in other branches
  1. 10 core/themes/olivero/olivero.theme \olivero_preprocess_field__comment()
  2. 11.x core/themes/olivero/olivero.theme \olivero_preprocess_field__comment()

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

File

core/themes/olivero/olivero.theme, line 521

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';
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.