public function LearningPathManagerController::addLink in Opigno Learning path 8
Same name and namespace in other branches
- 3.x src/Controller/LearningPathManagerController.php \Drupal\opigno_learning_path\Controller\LearningPathManagerController::addLink()
Add a new link in the Learning Path.
1 string reference to 'LearningPathManagerController::addLink'
File
- src/
Controller/ LearningPathManagerController.php, line 368
Class
- LearningPathManagerController
- Controller for all the actions of the Learning Path manager app.
Namespace
Drupal\opigno_learning_path\ControllerCode
public function addLink(Group $group, Request $request) {
// First, check if all 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 request params.
$parentCid = $datas->parentCid;
$childCid = $datas->childCid;
// Create the new link and return OK.
$new_link = LPManagedLink::createWithValues($group
->id(), $parentCid, $childCid, 0);
$new_link
->save();
return new JsonResponse(NULL, Response::HTTP_OK);
}