function opigno_learning_path_preprocess_opigno_certificate in Opigno Learning path 8
Implements template_preprocess_HOOK().
File
- ./
opigno_learning_path.module, line 622 - Contains opigno_learning_path.module.
Code
function opigno_learning_path_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) {
$completed = opigno_learning_path_completed_on($referencing_entity
->id(), \Drupal::currentUser()
->id(), TRUE);
if ($completed) {
$variables['completed_on'] = \Drupal::service('date.formatter')
->format($completed, 'custom', 'd/M/Y');
}
// @todo: add a proper API function to get courses for a learning path.
$managed_content = OpignoGroupManagedContent::loadByProperties([
'group_id' => $referencing_entity
->id(),
]);
$course_titles = [];
foreach ($managed_content as $content) {
// Need the content type object to get the LearningPathContent object.
$content_type_id = $content
->getGroupContentTypeId();
if ($content_type_id == 'ContentTypeCourse') {
$group = Group::load($content
->getEntityId());
$course_titles[] = $group
->label();
}
}
$variables['extra'] = implode(', ', $course_titles);
}
}