function hijri_preprocess_comment in Hijri 1.0.x
Same name and namespace in other branches
- 8.2 hijri.module \hijri_preprocess_comment()
- 8 hijri.module \hijri_preprocess_comment()
- 7 hijri.module \hijri_preprocess_comment()
- 3.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 148 - 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(array &$variables) {
$comment = $variables['elements']['#comment'];
$node = $comment
->getCommentedEntity();
$variables['comment'] = $comment;
$node_types = \Drupal::config('hijri.config')
->get('hijri_types');
$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':
$format = t('@hijri on @gregorian', [
'@hijri' => $hijri_formatter
->format($comment
->getCreatedTime(), 'custom', 'l j F Y'),
'@gregorian' => \Drupal::service('date.formatter')
->format($comment
->getCreatedTime(), 'custom', 'F j, Y'),
]);
break;
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', [
'@username' => $variables['author'],
'@datetime' => $format,
]);
$variables['created'] = $format;
}
}