public function OpignoGroupManagerController::removeItem in Opigno group manager 8
Same name and namespace in other branches
- 3.x src/Controller/OpignoGroupManagerController.php \Drupal\opigno_group_manager\Controller\OpignoGroupManagerController::removeItem()
Remove item from learning path.
1 string reference to 'OpignoGroupManagerController::removeItem'
File
- src/
Controller/ OpignoGroupManagerController.php, line 616
Class
- OpignoGroupManagerController
- Controller for all the actions of the Opigno group manager app.
Namespace
Drupal\opigno_group_manager\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 = OpignoGroupManagedContent::load($cid);
$learning_path_plugin = $lp_content_entity
->getGroupContentType();
$plugin_definition = $this->content_types_manager
->getDefinition($learning_path_plugin
->getPluginId());
if (!empty($plugin_definition['group_content_plugin_id'])) {
$lp_group = \Drupal::entityTypeManager()
->getStorage('group')
->load($lp_content_entity
->get('group_id')->entity
->id());
// Remove Learning path course if it's exist.
$group_contents = $lp_group
->getContentByEntityId($plugin_definition['group_content_plugin_id'], $lp_content_entity
->get('entity_id')->value);
if (!empty($group_contents)) {
// Probably, there can be a few same items. Get only last.
$group_content = end($group_contents);
$group_content
->delete();
}
}
// Then delete the content and return OK.
$lp_content_entity
->delete();
return new JsonResponse(NULL, Response::HTTP_OK);
}