You are here

public function LearningPathMembershipController::deleteClass in Opigno Learning path 8

Same name and namespace in other branches
  1. 3.x src/Controller/LearningPathMembershipController.php \Drupal\opigno_learning_path\Controller\LearningPathMembershipController::deleteClass()

Ajax callback used in opigno_learning_path_member_overview.js.

Removes class from learning path.

1 string reference to 'LearningPathMembershipController::deleteClass'
opigno_learning_path.routing.yml in ./opigno_learning_path.routing.yml
opigno_learning_path.routing.yml

File

src/Controller/LearningPathMembershipController.php, line 437

Class

LearningPathMembershipController
Controller for the actions related to LP membership.

Namespace

Drupal\opigno_learning_path\Controller

Code

public function deleteClass() {

  /** @var \Drupal\group\Entity\Group $group */
  $group = \Drupal::routeMatch()
    ->getParameter('group');
  $class_id = \Drupal::request()->query
    ->get('class_id');
  $class = Group::load($class_id);
  if (!isset($group) || !isset($class)) {
    throw new NotFoundHttpException();
  }
  $content = $group
    ->getContent();
  $account = $this
    ->currentUser();

  /** @var \Drupal\group\Entity\GroupContentInterface $item */
  foreach ($content as $item) {
    $entity = $item
      ->getEntity();
    $type = $entity
      ->getEntityTypeId();
    $bundle = $entity
      ->bundle();
    if ($type === 'group' && $bundle === 'opigno_class' && $entity
      ->id() === $class
      ->id()) {
      $item
        ->delete();
      break;
    }
  }
  return new JsonResponse();
}