You are here

public function SchemataJsonSchemaServiceProvider::register in Schemata 8

Registers services to the container.

Parameters

ContainerBuilder $container: The ContainerBuilder to register services to.

Overrides ServiceProviderInterface::register

File

schemata_json_schema/src/SchemataJsonSchemaServiceProvider.php, line 17

Class

SchemataJsonSchemaServiceProvider
Provides schemata services that depend directly on HAL.

Namespace

Drupal\schemata_json_schema

Code

public function register(ContainerBuilder $container) {
  $modules = $container
    ->getParameter('container.modules');
  if (isset($modules['jsonapi'])) {

    // Define encoder for schema_json:jsonapi.
    $container
      ->register('serializer.encoder.json_schema.jsonapi', 'Drupal\\schemata_json_schema\\Encoder\\JsonSchemaEncoder')
      ->addArgument(new Reference('serializer.encoder.jsonapi'))
      ->addTag('encoder', [
      'priority' => 10,
      'format' => 'schema_json',
    ]);
  }
  if (isset($modules['hal'])) {

    // Provide the HAL+JSON version of the Data Reference normalizer here
    // because the hal.link_manager service argument requires HAL.
    $container
      ->register('serializer.normalizer.data_reference_definition.schema_json.hal_json', 'Drupal\\schemata_json_schema\\Normalizer\\hal\\DataReferenceDefinitionNormalizer')
      ->addArgument(new Reference('entity_type.manager'))
      ->addArgument(new Reference('hal.link_manager'))
      ->addTag('normalizer', [
      'priority' => 30,
    ]);

    // Define encoder for schema_json:hal.
    $container
      ->register('serializer.encoder.json_schema.hal_json', 'Drupal\\schemata_json_schema\\Encoder\\JsonSchemaEncoder')
      ->addArgument(new Reference('serializer.encoder.hal'))
      ->addTag('encoder', [
      'priority' => 10,
      'format' => 'schema_json',
    ]);
  }
}