function opigno_learning_path_preprocess_region in Opigno Learning path 3.x
Same name and namespace in other branches
- 8 opigno_learning_path.module \opigno_learning_path_preprocess_region()
Implements hook_preprocess_region().
File
- ./
opigno_learning_path.module, line 410 - Contains opigno_learning_path.module.
Code
function opigno_learning_path_preprocess_region(&$variables) {
if (opigno_learning_path_is_lp_route() && $variables['region'] == 'content') {
$variables['step_list_top'] = opigno_learning_path_get_step_list_top();
$variables['step_list_aside'] = opigno_learning_path_get_step_list_aside();
$group = \Drupal::routeMatch()
->getParameter('group');
if ($group instanceof GroupInterface && \Drupal::routeMatch()
->getRouteName() != 'opigno_group_manager.manager.index' && \Drupal::routeMatch()
->getRouteName() != 'opigno_learning_path.learning_path_courses' && \Drupal::routeMatch()
->getRouteName() != 'opigno_learning_path.learning_path_modules') {
$current_step = opigno_learning_path_get_current_step();
// Check if training is published.
$is_published = $group
->hasField('field_learning_path_published') ? $group
->get('field_learning_path_published')
->getValue()[0]['value'] : TRUE;
$finish_text = !$is_published ? t('Publish') : Markup::create(t('Finish') . '<i class="fi fi-rr-rocket"></i>');
$next_step = $current_step < 5 ? $current_step + 1 : NULL;
$link_text = !$next_step ? $finish_text : Markup::create(t('Next') . '<i class="fi fi-rr-angle-small-right"></i>');
if (!$next_step && !$group
->access('update')) {
$variables['next_link'] = '';
}
else {
$variables['next_link'] = Link::createFromRoute($link_text, 'opigno_learning_path.content_steps', [
'group' => $group
->id(),
'current' => $current_step ? $current_step : 0,
], [
'attributes' => [
'class' => [
'btn',
'btn-rounded',
'current-step-' . $current_step,
],
'data-toggle' => 'trigger_click',
'data-target' => '#group-learning-path-edit-form .form-submit',
],
])
->toRenderable();
}
}
else {
$variables['next_link'] = '';
}
}
if (\Drupal::routeMatch()
->getRouteName() == 'opigno_learning_path.membership.overview' && $variables['region'] == 'content' && ($group = \Drupal::routeMatch()
->getParameter('group'))) {
$bundle = $group
->bundle();
// Limit the number of members in the class.
if (!($bundle == 'opigno_class') || count($group
->getMembers()) < 100) {
$link = Link::createFromRoute(Markup::create('<i class="fi fi-rr-user-add"></i>' . t('Add members')), 'entity.group_content.add_form', [
'group' => $group
->id(),
'plugin_id' => 'group_membership',
], [
'attributes' => [
'id' => 'btn_member_add',
'class' => [
'd-inline-flex',
'align-items-center',
'btn',
'btn-rounded',
],
],
])
->toRenderable();
$variables['add_member_link'] = render($link);
}
else {
$variables['add_member_link'] = [
'#type' => 'markup',
'#markup' => '<div class="class-limit-reached">' . t('A limit of the number of members in a class is reached.') . '</div>',
];
}
}
}