You are here

protected static function JsonApiGenerator::findDisabledMethods in OpenAPI for JSON:API 3.x

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

Introspects all the JSON API resource types and outputs the disabled ones.

Parameters

\Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager: The entity type manager.

\Drupal\jsonapi\ResourceType\ResourceTypeRepositoryInterface $resource_type_repository: The resource type manager.

Return value

string[] A list of resource keys to disable.

1 call to JsonApiGenerator::findDisabledMethods()
JsonApiGenerator::__construct in src/Plugin/openapi/OpenApiGenerator/JsonApiGenerator.php
JsonApiGenerator constructor.

File

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

Class

JsonApiGenerator
Defines an OpenApi Schema Generator for the JsonApi module.

Namespace

Drupal\openapi_jsonapi\Plugin\openapi\OpenApiGenerator

Code

protected static function findDisabledMethods(EntityTypeManagerInterface $entity_type_manager, ResourceTypeRepositoryInterface $resource_type_repository) {
  $extract_resource_type_id = function (ResourceType $resource_type) use ($entity_type_manager) {
    $entity_type = $entity_type_manager
      ->getDefinition($resource_type
      ->getEntityTypeId());
    if (empty($entity_type
      ->getKey('bundle'))) {
      return $resource_type
        ->getEntityTypeId();
    }
    return sprintf('%s%s%s', $resource_type
      ->getEntityTypeId(), static::$DEFINITION_SEPARATOR, $resource_type
      ->getBundle());
  };
  $filter_disabled = function (ResourceType $resourceType) {

    // If there is an isInternal method and the resource is marked as internal
    // then consider it disabled. If not, then it's enabled.
    return method_exists($resourceType, 'isInternal') && $resourceType
      ->isInternal();
  };
  $all = $resource_type_repository
    ->all();
  $disabled_resources = array_filter($all, $filter_disabled);
  $disabled = array_map($extract_resource_type_id, $disabled_resources);
  return $disabled;
}