You are here

protected function JsonApiSchemaController::getSchemaTitle in JSON:API Schema 8

Gets a schema title.

Parameters

\Drupal\jsonapi\ResourceType\ResourceType $resource_type: A JSON:API resource type for which to generate a title.

$schema_type: The type of schema. Either 'collection' or 'item'.

Return value

\Drupal\Core\StringTranslation\TranslatableMarkup The schema title.

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

3 calls to JsonApiSchemaController::getSchemaTitle()
JsonApiSchemaController::getDocumentSchema in src/Controller/JsonApiSchemaController.php
JsonApiSchemaController::getEntrypointSchema in src/Controller/JsonApiSchemaController.php
JsonApiSchemaController::getResourceObjectSchema in src/Controller/JsonApiSchemaController.php

File

src/Controller/JsonApiSchemaController.php, line 307

Class

JsonApiSchemaController

Namespace

Drupal\jsonapi_schema\Controller

Code

protected function getSchemaTitle(ResourceType $resource_type, $schema_type) {
  $entity_type = $this->entityTypeManager
    ->getDefinition($resource_type
    ->getEntityTypeId());
  $entity_type_label = $schema_type === 'collection' ? $entity_type
    ->getPluralLabel() : $entity_type
    ->getSingularLabel();
  if ($bundle_type = $entity_type
    ->getBundleEntityType()) {
    $bundle = $this->entityTypeManager
      ->getStorage($bundle_type)
      ->load($resource_type
      ->getBundle());
    return $this
      ->t(rtrim('@bundle_label @entity_type_label'), [
      '@bundle_label' => Unicode::ucfirst($bundle
        ->label()),
      '@entity_type_label' => $entity_type_label,
    ]);
  }
  else {
    return $this
      ->t(rtrim('@entity_type_label'), [
      '@entity_type_label' => Unicode::ucfirst($entity_type_label),
    ]);
  }
}