public function LearningPathManagerController::removeItem in Opigno Learning path 8
Same name and namespace in other branches
- 3.x src/Controller/LearningPathManagerController.php \Drupal\opigno_learning_path\Controller\LearningPathManagerController::removeItem()
Remove item from learning path.
1 string reference to 'LearningPathManagerController::removeItem'
File
- src/
Controller/ LearningPathManagerController.php, line 335
Class
- LearningPathManagerController
- Controller for all the actions of the Learning Path manager app.
Namespace
Drupal\opigno_learning_path\ControllerCode
public function removeItem(Request $request) {
// Get and check the params of the ajax request.
$datas = json_decode($request
->getContent());
if (empty($datas->cid)) {
return new JsonResponse(NULL, Response::HTTP_BAD_REQUEST);
}
$cid = $datas->cid;
// Load Learning path content entity.
$lp_content_entity = LPManagedContent::load($cid);
$learning_path_plugin = $lp_content_entity
->getLearningPathContentType();
/* @todo Update remove functionality when Module app implementation will be done. */
if ($learning_path_plugin
->getPluginId() == 'ContentTypeCourse') {
// Load Learning path group.
$lp_group = \Drupal::entityTypeManager()
->getStorage('group')
->load($lp_content_entity
->get('learning_path_id')->entity
->id());
// Remove Learning path course if it's exist.
$group_contents = $lp_group
->getContentByEntityId('subgroup:opigno_course', $lp_content_entity
->get('entity_id')->value);
if (!empty($group_contents)) {
foreach ($group_contents as $group_content) {
$group_content
->delete();
}
}
}
// Then delete the content and return OK.
$lp_content_entity
->delete();
return new JsonResponse(NULL, Response::HTTP_OK);
}