function template_preprocess_comment

Prepares variables for comment templates.

By default this function performs special preprocessing of some base fields so they are available as variables in the template. For example 'subject' appears as 'title'. This preprocessing is skipped if:

  • a module makes the field's display configurable via the field UI by means of BaseFieldDefinition::setDisplayConfigurable()
  • AND the additional entity type property 'enable_base_field_custom_preprocess_skipping' has been set using hook_entity_type_build().

Default template: comment.html.twig.

Parameters

array $variables: An associative array containing:

  • elements: An associative array containing the comment and entity objects. Array keys: #comment, #commented_entity.

Deprecated

in drupal:11.3.0 and is removed from drupal:12.0.0. Initial template_preprocess functions are registered directly in hook_theme().

See also

https://www.drupal.org/node/3504125

File

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

Code

function template_preprocess_comment(&$variables) : void {
  @trigger_error(__FUNCTION__ . '() is deprecated in drupal:11.3.0 and is removed from drupal:12.0.0. Initial template_preprocess functions are registered directly in hook_theme(). See https://www.drupal.org/node/3504125', E_USER_DEPRECATED);
  \Drupal::service(CommentThemeHooks::class)->preprocessComment($variables);
}

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