You are here

public function OpignoGroupManagerController::updateGuidedNavigation 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::updateGuidedNavigation()

Update Learning Path guided navigation field.

Parameters

\Drupal\group\Entity\Group $group: Group object.

\Symfony\Component\HttpFoundation\Request $request: Request array.

Return value

\Symfony\Component\HttpFoundation\JsonResponse Response array.

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

File

src/Controller/OpignoGroupManagerController.php, line 915

Class

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

Namespace

Drupal\opigno_group_manager\Controller

Code

public function updateGuidedNavigation(Group $group, Request $request) {
  $data = json_decode($request
    ->getContent());
  if (!isset($data->guidedNavigation)) {
    return new JsonResponse(NULL, Response::HTTP_BAD_REQUEST);
  }
  $guidedNavigation = 0;
  if ($group
    ->hasField('field_guided_navigation')) {
    $guidedNavigation = $data->guidedNavigation;
    $group
      ->set('field_guided_navigation', $guidedNavigation);
    try {
      $group
        ->save();
    } catch (EntityStorageException $e) {
      return new JsonResponse(NULL, Response::HTTP_INTERNAL_SERVER_ERROR);
    }
  }
  return new JsonResponse([
    'guidedNavigation' => $guidedNavigation,
  ], Response::HTTP_OK);
}