You are here

class DefaultContentExtraServiceProvider in Default Content Extras 8

Adds customized normalizer to handle taxonomy hierarchy.

Hierarchy

Expanded class hierarchy of DefaultContentExtraServiceProvider

File

src/DefaultContentExtraServiceProvider.php, line 13

Namespace

Drupal\default_content_extra
View source
class DefaultContentExtraServiceProvider extends ServiceProviderBase {

  /**
   * {@inheritdoc}
   */
  public function alter(ContainerBuilder $container) {
    $modules = $container
      ->getParameter('container.modules');

    // @todo Get rid of after https://www.drupal.org/node/2543726
    if (isset($modules['taxonomy'])) {

      // Add a normalizer service for term entities.
      $service_definition = new Definition('Drupal\\default_content_extra\\Normalizer\\TermEntityNormalizer', [
        new Reference('hal.link_manager'),
        new Reference('entity_type.manager'),
        new Reference('module_handler'),
        new Reference('entity_type.repository'),
        new Reference('entity_field.manager'),
        new Reference('config.factory'),
      ]);

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

}

Members

Namesort descending Modifiers Type Description Overrides
DefaultContentExtraServiceProvider::alter public function Modifies existing service definitions. Overrides ServiceProviderBase::alter
ServiceProviderBase::register public function Registers services to the container. Overrides ServiceProviderInterface::register 1