public function LearningPathManagerController::removeLink in Opigno Learning path 8
Same name and namespace in other branches
- 3.x src/Controller/LearningPathManagerController.php \Drupal\opigno_learning_path\Controller\LearningPathManagerController::removeLink()
Removes a link.
1 string reference to 'LearningPathManagerController::removeLink'
File
- src/
Controller/ LearningPathManagerController.php, line 450
Class
- LearningPathManagerController
- Controller for all the actions of the Learning Path manager app.
Namespace
Drupal\opigno_learning_path\ControllerCode
public function removeLink(Group $group, Request $request) {
// First, check that the params are okay.
$datas = json_decode($request
->getContent());
if (empty($datas->parentCid) || empty($datas->childCid)) {
return new JsonResponse(NULL, Response::HTTP_BAD_REQUEST);
}
// Get the params.
$parentCid = $datas->parentCid;
$childCid = $datas->childCid;
// Get the links. Should be only one.
try {
$links = LPManagedLink::loadByProperties([
'learning_path_id' => $group
->id(),
'parent_content_id' => $parentCid,
'child_content_id' => $childCid,
]);
} catch (InvalidPluginDefinitionException $e) {
return new JsonResponse(NULL, Response::HTTP_INTERNAL_SERVER_ERROR);
}
// Delete the links and return OK.
foreach ($links as $link) {
$link
->delete();
}
return new JsonResponse(NULL, Response::HTTP_OK);
}