You are here

function opigno_learning_path_tokens in Opigno Learning path 3.x

Same name and namespace in other branches
  1. 8 opigno_learning_path.tokens.inc \opigno_learning_path_tokens()

Implements hook_tokens().

File

./opigno_learning_path.tokens.inc, line 26
Builds placeholder replacement tokens for opigno_certificate-related data.

Code

function opigno_learning_path_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata) {
  $replacements = [];
  if ($type == 'group') {
    foreach ($tokens as $name => $original) {
      if ($name == 'expiration_date') {
        $type = '';
        if (!empty($data["group"]) && !empty($data["uid"])) {
          $group = $data["group"];
          $uid = $data["uid"];
          $type = !empty($data["expire_text_type"]) ? $data["expire_text_type"] : NULL;
        }
        elseif (!empty($data['opigno_certificate']->referencing_entity->entity)) {
          $group = $data['opigno_certificate']->referencing_entity->entity;
          $uid = \Drupal::currentUser()
            ->id();
          $type = 'valid';
        }
        if (!empty($group) && !empty($uid) && $group
          ->bundle() == 'learning_path') {
          $replacements[$original] = LPStatus::getCertificateExpirationMessage($group
            ->id(), $uid, $type);
        }
      }
    }
  }
  return $replacements;
}