You are here

AcquiaContentHubServiceProvider.php in Acquia Content Hub 8

File

src/AcquiaContentHubServiceProvider.php
View source
<?php

namespace Drupal\acquia_contenthub;

use Drupal\acquia_contenthub\EventSubscriber\View\RemovePageThemeWrapperSubscriber;
use Drupal\acquia_contenthub\EventSubscriber\View\RemovePageThemeWrapperSubscriberD9;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\DependencyInjection\ServiceProviderBase;
use Symfony\Component\DependencyInjection\Reference;

/**
 * Make sure it exposes the acquia_contenthub_cdf format as json.
 *
 * Alters the service definition for RemovePageThemeWrapperSubscriber.
 */
class AcquiaContentHubServiceProvider extends ServiceProviderBase {

  /**
   * {@inheritdoc}
   */
  public function alter(ContainerBuilder $container) {
    if ($container
      ->has('http_middleware.negotiation') && is_a($container
      ->getDefinition('http_middleware.negotiation')
      ->getClass(), '\\Drupal\\Core\\StackMiddleware\\NegotiationMiddleware', TRUE)) {
      $container
        ->getDefinition('http_middleware.negotiation')
        ->addMethodCall('registerFormat', [
        'acquia_contenthub_cdf',
        [
          'application/json',
        ],
      ]);
    }
  }

  /**
   * {@inheritDoc}
   */
  public function register(ContainerBuilder $container) {
    parent::register($container);
    if (version_compare(\Drupal::VERSION, '9.0.0', '>=')) {
      $class_name = RemovePageThemeWrapperSubscriberD9::class;
    }
    else {
      $class_name = RemovePageThemeWrapperSubscriber::class;
    }
    $container
      ->register('acquia_contenthub.page.theme_wrapper.view_subscriber', $class_name)
      ->addArgument(new Reference('class_resolver'))
      ->addArgument(new Reference('current_route_match'))
      ->addArgument('%main_content_renderers%')
      ->addTag('event_subscriber');
  }

}

Classes

Namesort descending Description
AcquiaContentHubServiceProvider Make sure it exposes the acquia_contenthub_cdf format as json.