comment_preprocess_field(&$variables)
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.
array $variables: An associative array containing:
function comment_preprocess_field(&$variables) { $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 (eg. RDFa) 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']; } }
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!modules!comment!comment.module/function/comment_preprocess_field/8.1.x