class JsonapiExtrasServiceProvider in JSON:API Extras 8
Same name and namespace in other branches
- 8.3 src/JsonapiExtrasServiceProvider.php \Drupal\jsonapi_extras\JsonapiExtrasServiceProvider
- 8.2 src/JsonapiExtrasServiceProvider.php \Drupal\jsonapi_extras\JsonapiExtrasServiceProvider
Replace the resource type repository for our own configurable version.
Hierarchy
- class \Drupal\Core\DependencyInjection\ServiceProviderBase implements ServiceModifierInterface, ServiceProviderInterface
- class \Drupal\jsonapi_extras\JsonapiExtrasServiceProvider
Expanded class hierarchy of JsonapiExtrasServiceProvider
File
- src/
JsonapiExtrasServiceProvider.php, line 13
Namespace
Drupal\jsonapi_extrasView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
JsonapiExtrasServiceProvider:: |
public | function |
Modifies existing service definitions. Overrides ServiceProviderBase:: |
|
JsonapiExtrasServiceProvider:: |
public | function |
Registers services to the container. Overrides ServiceProviderBase:: |