public function JsonapiHypermediaServiceProvider::alter in JSON:API Hypermedia 8
Modifies existing service definitions.
Parameters
ContainerBuilder $container: The ContainerBuilder whose service definitions can be altered.
Overrides ServiceProviderBase::alter
File
- src/
JsonapiHypermediaServiceProvider.php, line 22
Class
- JsonapiHypermediaServiceProvider
- Class JsonApiHypermediaServiceProvider.
Namespace
Drupal\jsonapi_hypermediaCode
public function alter(ContainerBuilder $container) {
// 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');
$impostor_path = dirname($container_modules['jsonapi_hypermedia']['pathname']) . '/src/Normalizer/JsonapiHypermediaImpostor';
$container_namespaces['Drupal\\jsonapi\\Normalizer\\JsonapiHypermediaImpostor'][] = $impostor_path;
$container
->getDefinition('serializer.normalizer.link_collection.jsonapi_hypermedia')
->setFile($impostor_path . '/JsonapiHypermediaLinkCollectionNormalizer.php');
$container
->setParameter('container.namespaces', $container_namespaces);
$definition = $container
->getDefinition('serializer.normalizer.link_collection.jsonapi_hypermedia');
foreach ($this
->findAndSortTaggedServices('jsonapi_hypermedia_provider', $container) as $id) {
$definition
->addMethodCall('addHypermediaProvider', [
new Reference($id),
]);
}
}