You are here

public function OpignoGroupManagerController::addLink in Opigno group manager 8

Same name and namespace in other branches
  1. 3.x src/Controller/OpignoGroupManagerController.php \Drupal\opigno_group_manager\Controller\OpignoGroupManagerController::addLink()

Add a new link in the Learning Path.

1 string reference to 'OpignoGroupManagerController::addLink'
opigno_group_manager.routing.yml in ./opigno_group_manager.routing.yml
opigno_group_manager.routing.yml

File

src/Controller/OpignoGroupManagerController.php, line 648

Class

OpignoGroupManagerController
Controller for all the actions of the Opigno group manager app.

Namespace

Drupal\opigno_group_manager\Controller

Code

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 = OpignoGroupManagedLink::createWithValues($group
    ->id(), $parentCid, $childCid, 0);
  $new_link
    ->save();
  return new JsonResponse(NULL, Response::HTTP_OK);
}