You are here

class JsonapiExtrasServiceProvider in JSON:API Extras 8

Same name and namespace in other branches
  1. 8.3 src/JsonapiExtrasServiceProvider.php \Drupal\jsonapi_extras\JsonapiExtrasServiceProvider
  2. 8.2 src/JsonapiExtrasServiceProvider.php \Drupal\jsonapi_extras\JsonapiExtrasServiceProvider

Replace the resource type repository for our own configurable version.

Hierarchy

Expanded class hierarchy of JsonapiExtrasServiceProvider

File

src/JsonapiExtrasServiceProvider.php, line 13

Namespace

Drupal\jsonapi_extras
View source
class JsonapiExtrasServiceProvider extends ServiceProviderBase {

  /**
   * {@inheritdoc}
   */
  public function alter(ContainerBuilder $container) {
    if ($container
      ->has('jsonapi.resource_type.repository')) {

      // Override the class used for the configurable service.
      $definition = $container
        ->getDefinition('jsonapi.resource_type.repository');
      $definition
        ->setClass(ConfigurableResourceTypeRepository::class);

      // The configurable service expects the entity repository and the enhancer
      // plugin manager.
      $definition
        ->addArgument(new Reference('entity.repository'));
      $definition
        ->addArgument(new Reference('plugin.manager.resource_field_enhancer'));
      $definition
        ->addArgument(new Reference('config.factory'));
    }
  }

  /**
   * {@inheritdoc}
   */
  public function register(ContainerBuilder $container) {
    $modules = $container
      ->getParameter('container.modules');
    if (isset($modules['schemata_json_schema'])) {

      // Register field definition schema override.
      $container
        ->register('serializer.normalizer.field_definition.schema_json.jsonapi_extras', 'Drupal\\jsonapi_extras\\Normalizer\\SchemaFieldDefinitionNormalizer')
        ->addTag('normalizer', [
        'priority' => 32,
      ])
        ->addArgument(new Reference('jsonapi.resource_type.repository'));

      // Register top-level schema override.
      $container
        ->register('serializer.normalizer.schemata_schema_normalizer.schema_json.jsonapi_extras', 'Drupal\\jsonapi_extras\\Normalizer\\SchemataSchemaNormalizer')
        ->addTag('normalizer', [
        'priority' => 100,
      ])
        ->addArgument(new Reference('jsonapi.resource_type.repository'));
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
JsonapiExtrasServiceProvider::alter public function Modifies existing service definitions. Overrides ServiceProviderBase::alter
JsonapiExtrasServiceProvider::register public function Registers services to the container. Overrides ServiceProviderBase::register