You are here

function hijri_preprocess_node in Hijri 8

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

Prepares variables for node templates.

Default template: node.html.twig.

Most themes use their own copy of node.html.twig. The default is located inside "/core/modules/node/templates/node.html.twig". Look in there for the full list of variables.

Parameters

array $variables: An associative array containing:

  • elements: An array of elements to display in view mode.
  • node: The node object.
  • view_mode: View mode; e.g., 'full', 'teaser', etc.

File

./hijri.module, line 200
hijri.module This module convert to Hijri date in nodes,comments and a block.

Code

function hijri_preprocess_node(&$variables) {
  $node = $variables['node'];
  $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_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($node
          ->getCreatedTime(), $hijri_display, NULL, $correction);
        break;
      default:
        $format = $node
          ->getCreatedTime();
        break;
    }
    $node_type = $node->type->entity;

    // Display post information only on certain node types.
    if ($node_type
      ->displaySubmitted()) {
      $variables['display_submitted'] = TRUE;
      $variables['date'] = $format;
    }
  }
}