function OliveroHooks::preprocessFieldComment
Same name and namespace in other branches
- 11.x core/themes/olivero/src/Hook/OliveroHooks.php \Drupal\olivero\Hook\OliveroHooks::preprocessFieldComment()
Implements hook_preprocess_HOOK() for field--comment.
Attributes
#[Hook('preprocess_field__comment')]
File
-
core/
themes/ olivero/ src/ Hook/ OliveroHooks.php, line 511
Class
- OliveroHooks
- Hook implementations for olivero.
Namespace
Drupal\olivero\HookCode
public function preprocessFieldComment(&$variables) : void {
// 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.