You are here

public function LearningPathManagerController::getItemTypes in Opigno Learning path 3.x

Same name and namespace in other branches
  1. 8 src/Controller/LearningPathManagerController.php \Drupal\opigno_learning_path\Controller\LearningPathManagerController::getItemTypes()

Return content types available for learning paths.

1 string reference to 'LearningPathManagerController::getItemTypes'
opigno_learning_path.routing.yml in ./opigno_learning_path.routing.yml
opigno_learning_path.routing.yml

File

src/Controller/LearningPathManagerController.php, line 511

Class

LearningPathManagerController
Controller for all the actions of the Learning Path manager app.

Namespace

Drupal\opigno_learning_path\Controller

Code

public function getItemTypes($mainItem = NULL, $json_output = TRUE) {

  // Init the return array and get all the content types available.
  $available_types = [];
  $content_types_definitions = $this->content_types_manager
    ->getDefinitions();

  // For each content type available,
  // convert it to an array and store it in the return array.
  foreach ($content_types_definitions as $content_type_definition) {
    $available_types[] = [
      'bundle' => $content_type_definition['id'],
      'contentType' => $content_type_definition['id'],
      'name' => $content_type_definition['readable_name'],
    ];
  }

  // If a JSON response is asked, return JSON.
  // Else, return the array.
  if ($json_output) {
    return new JsonResponse($available_types, Response::HTTP_OK);
  }
  else {
    return $available_types;
  }
}