You are here

protected function JsonApiGenerator::getRouteMethodSummary in OpenAPI 8

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
Returns the paths information.

File

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

Class

JsonApiGenerator
Defines an OpenApi Schema Generator for the JsonApi module.

Namespace

Drupal\openapi\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),
  ]);
}