You are here

protected function JsonApiGenerator::getRouteMethodSummary 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::getRouteMethodSummary()

Gets description of a method on a route.

Parameters

\Symfony\Component\Routing\Route $route: The route.

string $route_name: The route name.

string $method: The method.

Return value

string The method summary.

1 call to JsonApiGenerator::getRouteMethodSummary()
JsonApiGenerator::getPaths in src/Plugin/openapi/OpenApiGenerator/JsonApiGenerator.php

File

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

Class

JsonApiGenerator
Defines an OpenApi Schema Generator for the JsonApi module.

Namespace

Drupal\openapi_jsonapi\Plugin\openapi\OpenApiGenerator

Code

protected function getRouteMethodSummary(Route $route, $route_name, $method) {
  $resource_type = $this
    ->getResourceType($route_name, $route);
  $entity_type_id = $resource_type
    ->getEntityTypeId();
  $bundle = $resource_type
    ->getBundle();
  $tag = $this
    ->getBundleTag($entity_type_id, $bundle);
  $route_type = $this
    ->getRoutTypeFromName($route_name);
  if (in_array($route_type, [
    'related',
    'relationship',
  ])) {
    $target_resource_type = $this
      ->relatedResourceType($route_name, $route);
    $target_tag = $this
      ->getBundleTag($target_resource_type
      ->getEntityTypeId(), $target_resource_type
      ->getBundle());
    return $this
      ->t('@route_type: @fieldName (@targetType)', [
      '@route_type' => ucfirst($route_type),
      '@fieldName' => explode('.', $route_name)[2],
      '@targetType' => $target_tag,
      '@tag' => $tag,
    ]);
  }
  if ($route_type === 'collection') {
    if ($method === 'get') {
      return $this
        ->t('List (@tag)', [
        '@tag' => $tag,
      ]);
    }
    if ($method === 'post') {
      return $this
        ->t('Create (@tag)', [
        '@tag' => $tag,
      ]);
    }
  }
  if ($route_type === 'individual') {
    if ($method === 'get') {
      return $this
        ->t('View (@tag)', [
        '@tag' => $tag,
      ]);
    }
    if ($method === 'patch') {
      return $this
        ->t('Update (@tag)', [
        '@tag' => $tag,
      ]);
    }
    if ($method === 'delete') {
      return $this
        ->t('Remove (@tag)', [
        '@tag' => $tag,
      ]);
    }
  }
  return $this
    ->t('@route_type @method', [
    '@route_type' => ucfirst($route_type),
    '@method' => strtoupper($method),
  ]);
}