You are here

public function YamlformServiceProvider::alter in YAML Form 8

Modifies existing service definitions.

Parameters

ContainerBuilder $container: The ContainerBuilder whose service definitions can be altered.

Overrides ServiceProviderBase::alter

File

src/YamlformServiceProvider.php, line 18

Class

YamlformServiceProvider
Service Provider for Yamlform.

Namespace

Drupal\yamlform

Code

public function alter(ContainerBuilder $container) {
  $modules = $container
    ->getParameter('container.modules');
  if (isset($modules['hal'])) {

    // Hal module is enabled, add our new normalizer for yamlform items.
    $service_definition = new Definition('Drupal\\yamlform\\Normalizer\\YamlFormEntityReferenceItemNormalizer', [
      new Reference('rest.link_manager'),
      new Reference('serializer.entity_resolver'),
    ]);

    // The priority must be higher than that of
    // serializer.normalizer.entity_reference_item.hal in
    // hal.services.yml.
    $service_definition
      ->addTag('normalizer', [
      'priority' => 20,
    ]);
    $container
      ->setDefinition('serializer.normalizer.yamlform_entity_reference_item', $service_definition);
  }
}