You are here

function template_preprocess_opigno_certificate in Opigno certificate 8

Same name and namespace in other branches
  1. 3.x opigno_certificate.module \template_preprocess_opigno_certificate()

Implements template_preprocess_HOOK().

File

./opigno_certificate.module, line 218
Contains opigno_certificate.module.

Code

function template_preprocess_opigno_certificate(array &$variables) {

  /** @var \Drupal\opigno_certificate\CertificateInterface $opigno_certificate */
  $opigno_certificate = $variables['elements']['#opigno_certificate'];

  /** @var \Drupal\Core\Entity\ContentEntityInterface $referencing_entity */
  $referencing_entity = $opigno_certificate->referencing_entity->entity;

  // Provide the referencing entity context.
  if ($referencing_entity) {
    $variables['referencing_entity'] = $referencing_entity;
    if ($opigno_certificate
      ->getViewModeSelectorField()) {
      $variables['content']['referencing_entity'] = [
        '#markup' => $referencing_entity
          ->label(),
      ];
    }
  }

  // Set today's date for completion date, modules referencing certificates
  // should set this in their own preprocess.
  $variables['completed_on'] = \Drupal::service('date.formatter')
    ->format(\Drupal::time()
    ->getRequestTime(), 'custom', 'd/M/Y');
  $variables['awarded_to'] = \Drupal::currentUser()
    ->getDisplayName();

  // Helpful $content variable for templates.
  foreach (Element::children($variables['elements']) as $key) {
    $variables['content'][$key] = $variables['elements'][$key];
  }
  $variables['style_certificate_edit_form'] = drupal_get_path('module', 'opigno_certificate') . '/css/opigno_certificate_edit_form.css';
}