You are here

function template_preprocess_uikit_comment in UIkit Components 8.3

Prrpares variables for UIkit Comment templates.

Default template: uikit-comment.html.twig.

Parameters

$variables:: An associative array containing:

  • element: An associative array containing:

    • #avatar: An assocative array containing:

      • style_name: The name of the image style to be applied.
      • uri: URI of the source image before styling.
      • height: The height of the image.
      • width: The width of the image.
      • alt: The alternative text for text-based browsers. HTML 4 and XHTML 1.0 always require an alt attribute. The HTML 5 draft allows the alt attribute to be omitted in some cases. Therefore, this variable defaults to an empty string, but can be set to NULL for the attribute to be omitted. Usually, neither omission nor an empty string satisfies accessibility requirements, so it is strongly encouraged for code using '#theme' => 'image_style' to pass a meaningful value for this variable.

      • title: The title text is displayed when the image is hovered in some popular browsers.
      • attributes: Associative array of attributes to be placed in the img tag.
    • #title: The title to display in the comment header.
    • #meta: An array containing the metadata to display in the comment header.
    • #comment: The content to display for the comment body.

See also

template_preprocess_image_style()

\Drupal\uikit_components\Element\UIkitComment

https://getuikit.com/docs/comment

Related topics

File

includes/preprocess.inc, line 330
Set up variables to be placed within the template (.html.twig) files.

Code

function template_preprocess_uikit_comment(&$variables) {
  $element = $variables['element'];

  // Set the attributes for the comment.
  $variables['attributes'] = $element['#attributes'];

  // Set the avatar, title, metadata and comment variables, if not empty.
  if (!empty($element['#avatar'])) {
    $variables['avatar'] = $element['#avatar'];
  }
  if (!empty($element['#title'])) {
    $variables['title'] = $element['#title'];
  }
  if (!empty($element['#meta'])) {
    $variables['meta'] = $element['#meta'];
  }
  if (!empty($element['#comment'])) {
    $variables['comment'] = $element['#comment'];
  }
}