Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. comment.module

function comment_preprocess_field

Prepares variables for comment field templates.

Default template: field--comment.html.twig.

@todo Rename to template_preprocess_field__comment() once https://www.drupal.org/node/939462 is resolved.

Parameters

array $variables: An associative array containing:

  • element: An associative array containing render arrays for the list of comments, and the comment form. Array keys: comments, comment_form.

File

core/modules/comment/comment.module, line 281

Code

function comment_preprocess_field(&$variables) : void {
    $element = $variables['element'];
    if ($element['#field_type'] == 'comment') {
        // Provide contextual information.
        $variables['comment_display_mode'] = $element[0]['#comment_display_mode'];
        $variables['comment_type'] = $element[0]['#comment_type'];
        // Append additional attributes from the first field item.
        $variables['attributes'] += $variables['items'][0]['attributes']->storage();
        // Create separate variables for the comments and comment form.
        $variables['comments'] = $element[0]['comments'];
        $variables['comment_form'] = $element[0]['comment_form'];
    }
}
RSS feed
Powered by Drupal