public function LearningPathManagerController::updateItemMandatory in Opigno Learning path 8
Same name and namespace in other branches
- 3.x src/Controller/LearningPathManagerController.php \Drupal\opigno_learning_path\Controller\LearningPathManagerController::updateItemMandatory()
Method called when a step is set as mandatory or not.
1 string reference to 'LearningPathManagerController::updateItemMandatory'
File
- src/
Controller/ LearningPathManagerController.php, line 169
Class
- LearningPathManagerController
- Controller for all the actions of the Learning Path manager app.
Namespace
Drupal\opigno_learning_path\ControllerCode
public function updateItemMandatory(Group $group, Request $request) {
// Get the data and ensure that all data are okay.
$datas = json_decode($request
->getContent());
if (empty($datas->cid) || isset($datas->isMandatory) === FALSE) {
return new JsonResponse(NULL, Response::HTTP_BAD_REQUEST);
}
$cid = $datas->cid;
$mandatory = $datas->isMandatory;
// Load the good content, update it and save it.
$content = LPManagedContent::load($cid);
$content
->setMandatory($mandatory);
$content
->save();
// Finally, return the JSON response.
return new JsonResponse(NULL, Response::HTTP_OK);
}