public function FileEntityServiceProvider::alter in File Entity (fieldable files) 8.2
Modifies existing service definitions.
Parameters
ContainerBuilder $container: The ContainerBuilder whose service definitions can be altered.
Overrides ServiceProviderBase::alter
File
- src/
FileEntityServiceProvider.php, line 20
Class
- FileEntityServiceProvider
- Service Provider for File entity.
Namespace
Drupal\file_entityCode
public function alter(ContainerBuilder $container) {
$modules = $container
->getParameter('container.modules');
if (isset($modules['hal'])) {
// Add a normalizer service for file entities.
$service_definition = new Definition(FileEntityNormalizer::class, array(
new Reference('hal.link_manager'),
new Reference('entity_type.manager'),
new Reference('module_handler'),
new Reference('entity_type.repository'),
new Reference('entity_field.manager'),
));
// The priority must be higher than that of
// serializer.normalizer.file_entity.hal in hal.services.yml
$service_definition
->addTag('normalizer', array(
'priority' => 30,
));
$container
->setDefinition('serializer.normalizer.entity.file_entity', $service_definition);
// Add a normalizer service for file fields.
$service_definition = new Definition(FileItemNormalizer::class, array(
new Reference('hal.link_manager'),
new Reference('serializer.entity_resolver'),
));
// Supersede EntityReferenceItemNormalizer.
$service_definition
->addTag('normalizer', array(
'priority' => 20,
));
$container
->setDefinition('serializer.normalizer.entity_reference_item.file_entity', $service_definition);
}
}