You are here

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

Return contents availables when you want add content to learning path.

Parameters

int $mainItem: The main level content ID.

Return value

\Symfony\Component\HttpFoundation\JsonResponse Response.

Throws

\Drupal\Component\Plugin\Exception\PluginException

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

File

src/Controller/OpignoGroupManagerController.php, line 772

Class

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

Namespace

Drupal\opigno_group_manager\Controller

Code

public function getAvailableItems($mainItem = NULL) {

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

  // For each content type,
  // get the available contents from them and store it in the return array.
  foreach ($content_types_definitions as $content_type_id => $content_type_definition) {

    // Get the available contents from the content type.
    $content_type = $this->content_types_manager
      ->createInstance($content_type_id);
    $content_type_contents = $content_type
      ->getAvailableContents();

    // For each content, convert it to an array.
    foreach ($content_type_contents as $content_type_content) {
      $available_contents[] = $content_type_content
        ->toManagerArray();
    }
  }

  // Return the available contents in JSON.
  return new JsonResponse($available_contents, Response::HTTP_OK);
}