You are here

public function MetatagServiceProvider::alter in Metatag 8

Modifies existing service definitions.

Parameters

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

Overrides ServiceProviderBase::alter

File

src/MetatagServiceProvider.php, line 19

Class

MetatagServiceProvider
Service Provider for Metatag.

Namespace

Drupal\metatag

Code

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

    // Serialization module is enabled, add our metatag normalizers.
    // Priority of the metatag normalizer must be higher than other
    // general-purpose typed data and field item normalizers.
    $metatag = new Definition(MetatagNormalizer::class);
    $metatag
      ->addTag('normalizer', [
      'priority' => 30,
    ]);
    $container
      ->setDefinition('metatag.normalizer.metatag', $metatag);
    $metatag_hal = new Definition(MetatagHalNormalizer::class);
    $metatag_hal
      ->addTag('normalizer', [
      'priority' => 31,
    ]);
    $container
      ->setDefinition('metatag.normalizer.metatag.hal', $metatag_hal);
  }
}