You are here

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

Return content types available for learning paths.

Parameters

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

bool $json_output: JSON format flag.

Return value

array|\Symfony\Component\HttpFoundation\JsonResponse Response.

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

File

src/Controller/OpignoGroupManagerController.php, line 805

Class

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

Namespace

Drupal\opigno_group_manager\Controller

Code

public function getItemTypes(Group $group, $json_output = TRUE) {

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

  // Get the group bundle name.
  $group_type = $group
    ->getGroupType();

  // Check if module 'Opigno Moxtra' is enabled and configured.
  $moxtra_status = \Drupal::moduleHandler()
    ->moduleExists('opigno_moxtra') && _opigno_moxtra_get_organization_status();

  // 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) {

    // Add available content type only if it's allowed by plugin.
    if (in_array($group_type
      ->id(), $content_type_definition['allowed_group_types'])) {
      if ($content_type_definition['id'] == 'ContentTypeMeeting' && !$moxtra_status) {
        continue;
      }
      $available_types[] = [
        'bundle' => $content_type_definition['id'],
        'contentType' => $content_type_definition['id'],
        'name' => $this
          ->t($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;
  }
}