function opigno_learning_path_tokens in Opigno Learning path 8
Same name and namespace in other branches
- 3.x 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;
}