You are here

function hijri_preprocess_node in Hijri 8.2

Same name and namespace in other branches
  1. 8 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 96
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_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');

  /** @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($node
          ->getCreatedTime(), $hijri_display);
        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;
    }
  }
}