public function JsonapiExtrasServiceProvider::alter in JSON:API Extras 8.3
Same name and namespace in other branches
- 8 src/JsonapiExtrasServiceProvider.php \Drupal\jsonapi_extras\JsonapiExtrasServiceProvider::alter()
- 8.2 src/JsonapiExtrasServiceProvider.php \Drupal\jsonapi_extras\JsonapiExtrasServiceProvider::alter()
Modifies existing service definitions.
Parameters
ContainerBuilder $container: The ContainerBuilder whose service definitions can be altered.
Overrides ServiceProviderBase::alter
File
- src/
JsonapiExtrasServiceProvider.php, line 18
Class
- JsonapiExtrasServiceProvider
- Replace the resource type repository for our own configurable version.
Namespace
Drupal\jsonapi_extrasCode
public function alter(ContainerBuilder $container) {
$settings = BootstrapConfigStorageFactory::get()
->read('jsonapi_extras.settings');
if ($settings !== FALSE) {
$container
->setParameter('jsonapi.base_path', '/' . $settings['path_prefix']);
}
// Enable normalizers in the "src-impostor-normalizers" directory to be
// within the \Drupal\jsonapi\Normalizer namespace in order to circumvent
// the encapsulation enforced by
// \Drupal\jsonapi\Serializer\Serializer::__construct().
$container_namespaces = $container
->getParameter('container.namespaces');
$container_modules = $container
->getParameter('container.modules');
$jsonapi_impostor_path = dirname($container_modules['jsonapi_extras']['pathname']) . '/src-impostor-normalizers';
$container_namespaces['Drupal\\jsonapi\\Normalizer\\ImpostorFrom\\jsonapi_extras'][] = $jsonapi_impostor_path;
// Manually include the impostor definitions to avoid class not found error
// during compilation, which gets triggered though cache-clear.
$container
->getDefinition('serializer.normalizer.field_item.jsonapi_extras')
->setFile($jsonapi_impostor_path . '/FieldItemNormalizerImpostor.php');
$container
->getDefinition('serializer.normalizer.resource_identifier.jsonapi_extras')
->setFile($jsonapi_impostor_path . '/ResourceIdentifierNormalizerImpostor.php');
$container
->getDefinition('serializer.normalizer.resource_object.jsonapi_extras')
->setFile($jsonapi_impostor_path . '/ResourceObjectNormalizerImpostor.php');
$container
->getDefinition('serializer.normalizer.content_entity.jsonapi_extras')
->setFile($jsonapi_impostor_path . '/ContentEntityDenormalizerImpostor.php');
$container
->getDefinition('serializer.normalizer.config_entity.jsonapi_extras')
->setFile($jsonapi_impostor_path . '/ConfigEntityDenormalizerImpostor.php');
$container
->setParameter('container.namespaces', $container_namespaces);
}