You are here

function hijri_preprocess_comment in Hijri 8

Same name and namespace in other branches
  1. 8.2 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 241
hijri.module This module convert to Hijri date in nodes,comments and a block.

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');
  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_format_date($comment
          ->getCreatedTime(), $hijri_display, NULL, $correction);
        break;
      default:
        $format = $variables['created'];
        break;
    }
    $variables['submitted'] = t('Submitted by @username on @datetime', array(
      '@username' => $variables['author'],
      '@datetime' => $format,
    ));
    $variables['created'] = $format;
  }
}