You are here

public function JsonApiGenerator::getTags in OpenAPI for JSON:API 8.2

Same name and namespace in other branches
  1. 3.x src/Plugin/openapi/OpenApiGenerator/JsonApiGenerator.php \Drupal\openapi_jsonapi\Plugin\openapi\OpenApiGenerator\JsonApiGenerator::getTags()

File

src/Plugin/openapi/OpenApiGenerator/JsonApiGenerator.php, line 793

Class

JsonApiGenerator
Defines an OpenApi Schema Generator for the JsonApi module.

Namespace

Drupal\openapi_jsonapi\Plugin\openapi\OpenApiGenerator

Code

public function getTags() {
  $tags = [];
  foreach ($this->entityTypeManager
    ->getDefinitions() as $entity_type) {
    if ($bundle_type_id = $entity_type
      ->getBundleEntityType()) {
      $bundle_storage = $this->entityTypeManager
        ->getStorage($bundle_type_id);
      $bundles = $bundle_storage
        ->loadMultiple();
      foreach ($bundles as $bundle_name => $bundle) {
        if (!$this
          ->includeEntityTypeBundle($entity_type
          ->id(), $bundle_name)) {
          continue;
        }
        $description = $this
          ->t("@bundle_label @bundle of type @entity_type.", [
          '@bundle_label' => $entity_type
            ->getBundleLabel(),
          '@bundle' => $bundle
            ->label(),
          '@entity_type' => $entity_type
            ->getLabel(),
        ]);
        $tag = [
          'name' => $this
            ->getBundleTag($entity_type
            ->id(), $bundle
            ->id()),
          'description' => $description,
          'x-entity-type' => $entity_type
            ->id(),
          'x-definition' => [
            '$ref' => $this
              ->getDefinitionReference($entity_type
              ->id(), $bundle_name),
          ],
        ];
        if (method_exists($bundle, 'getDescription')) {
          $tag['description'] .= ' ' . $bundle
            ->getDescription();
        }
        $tags[] = $tag;
      }
    }
    else {
      if (!$this
        ->includeEntityTypeBundle($entity_type
        ->id())) {
        continue;
      }
      $tag = [
        'name' => $this
          ->getBundleTag($entity_type
          ->id()),
      ];
      if ($entity_type instanceof ConfigEntityTypeInterface) {
        $tag['description'] = $this
          ->t('Configuration entity @entity_type', [
          '@entity_type' => $entity_type
            ->getLabel(),
        ]);
      }
      $tags[] = $tag;
    }
  }
  return $tags;
}