You are here

YamlformServiceProvider.php in YAML Form 8

Namespace

Drupal\yamlform

File

src/YamlformServiceProvider.php
View source
<?php

namespace Drupal\yamlform;

use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\DependencyInjection\ServiceProviderBase;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;

/**
 * Service Provider for Yamlform.
 */
class YamlformServiceProvider extends ServiceProviderBase {

  /**
   * {@inheritdoc}
   */
  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);
    }
  }

}

Classes

Namesort descending Description
YamlformServiceProvider Service Provider for Yamlform.