public function LearningPathStepsController::nextStep in Opigno Learning path 3.x
Same name and namespace in other branches
- 8 src/Controller/LearningPathStepsController.php \Drupal\opigno_learning_path\Controller\LearningPathStepsController::nextStep()
Redirect the user to the next step.
1 string reference to 'LearningPathStepsController::nextStep'
File
- src/
Controller/ LearningPathStepsController.php, line 613
Class
- LearningPathStepsController
- Class LearningPathStepsController.
Namespace
Drupal\opigno_learning_path\ControllerCode
public function nextStep(Group $group, OpignoGroupManagedContent $parent_content, $content_update = TRUE) {
$next_step = $this
->getNextStep($group, $parent_content, $content_update);
// If there is no next step, show a message.
if ($next_step === NULL) {
// Redirect to training home page.
$this
->messenger()
->addWarning($this
->t('You reached the last content of that training.'));
return $this
->redirect('entity.group.canonical', [
'group' => $group
->id(),
]);
}
if (!isset($next_step['cid'])) {
return $next_step;
}
// Load next step entity.
$next_step = OpignoGroupManagedContent::load($next_step['cid']);
// Before redirect, change the content context.
if ($content_update) {
$this
->setGroupAndContext($group
->id(), $next_step
->id());
}
// Finally, redirect the user to the next step URL.
$next_step_content_type = $this->content_type_manager
->createInstance($next_step
->getGroupContentTypeId());
$next_step_url = $next_step_content_type
->getStartContentUrl($next_step
->getEntityId(), $group
->id());
return $this
->redirect($next_step_url
->getRouteName(), $next_step_url
->getRouteParameters(), $next_step_url
->getOptions());
}