public function LearningPathContentController::getCourses in Opigno Learning path 8
Same name and namespace in other branches
- 3.x src/Controller/LearningPathContentController.php \Drupal\opigno_learning_path\Controller\LearningPathContentController::getCourses()
This method is called on learning path load.
It returns all the LP courses in JSON format.
Parameters
\Drupal\group\Entity\Group $group: Group.
Return value
\Symfony\Component\HttpFoundation\JsonResponse Response.
1 string reference to 'LearningPathContentController::getCourses'
File
- src/
Controller/ LearningPathContentController.php, line 174
Class
- LearningPathContentController
- Controller for all the actions of the Learning Path content.
Namespace
Drupal\opigno_learning_path\ControllerCode
public function getCourses(Group $group) {
// Init the response and get all the contents from this learning path.
$courses = [];
$group_content = $group
->getContent('subgroup:opigno_course');
foreach ($group_content as $content) {
/* @var $content \Drupal\group\Entity\GroupContent */
/* @var $content_entity \Drupal\group\Entity\Group */
$content_entity = $content
->getEntity();
$courses[] = [
'entity_id' => $content_entity
->id(),
'name' => $content_entity
->label(),
];
}
// Return all the contents in JSON format.
return new JsonResponse($courses, Response::HTTP_OK);
}