You are here

function hijri_preprocess_comment in Hijri 8.2

Same name and namespace in other branches
  1. 8 hijri.module \hijri_preprocess_comment()
  2. 7 hijri.module \hijri_preprocess_comment()
  3. 3.0.x hijri.module \hijri_preprocess_comment()
  4. 1.0.x hijri.module \hijri_preprocess_comment()

Prepares variables for comment templates.

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.

File

./hijri.module, line 139
This module provides Hijri Date integration with Drupal core date field and with other Drupal contributions such as Views and Date.

Code

function hijri_preprocess_comment(&$variables) {
  $comment = $variables['elements']['#comment'];
  $node = $comment
    ->getCommentedEntity();
  $variables['comment'] = $comment;
  $node_types = \Drupal::config('hijri.config')
    ->get('hijri_types');
  $correction = \Drupal::config('hijri.config')
    ->get('correction_value');
  $hijri_display = \Drupal::config('hijri.config')
    ->get('hijri_comment_display');

  /** @var \Drupal\hijri\HijriFormatter $hijri_formatter */
  $hijri_formatter = \Drupal::service('hijri.formatter');
  if (isset($node_types[$node
    ->getType()]) && (string) $node_types[$node
    ->getType()] == $node
    ->getType()) {
    switch ($hijri_display) {
      case 'full':
      case 'long':
      case 'medium':
      case 'short':
        $format = $hijri_formatter
          ->format($comment
          ->getCreatedTime(), $hijri_display);
        break;
      default:
        $format = $variables['created'];
        break;
    }
    $variables['submitted'] = t('Submitted by @username on @datetime', array(
      '@username' => $variables['author'],
      '@datetime' => $format,
    ));
    $variables['created'] = $format;
  }
}