You are here

public function MultiversionServiceProvider::alter in Multiversion 8

Same name and namespace in other branches
  1. 8.2 src/MultiversionServiceProvider.php \Drupal\multiversion\MultiversionServiceProvider::alter()

Modifies existing service definitions.

Parameters

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

Overrides ServiceProviderBase::alter

File

src/MultiversionServiceProvider.php, line 15

Class

MultiversionServiceProvider
Defines a service profiler for the multiversion module.

Namespace

Drupal\multiversion

Code

public function alter(ContainerBuilder $container) {
  $renderer_config = $container
    ->getParameter('renderer.config');
  $renderer_config['required_cache_contexts'][] = 'workspace';
  $container
    ->setParameter('renderer.config', $renderer_config);

  // Switch the menu tree storage to our own that respect Workspace cache
  // contexts.
  $definition = $container
    ->getDefinition('menu.tree_storage');
  $definition
    ->setClass('Drupal\\multiversion\\MenuTreeStorage');

  // Override the comment.statistics class with a new class.
  try {
    $definition = $container
      ->getDefinition('comment.statistics');
    $definition
      ->setClass('Drupal\\multiversion\\CommentStatistics');
  } catch (InvalidArgumentException $e) {

    // Do nothing, comment module is not installed.
  }

  // Override the redirect.repository class with a new class.
  try {
    $definition = $container
      ->getDefinition('redirect.repository');
    $definition
      ->setClass('Drupal\\multiversion\\Redirect\\RedirectRepository')
      ->addArgument(new Reference('workspace.manager'))
      ->addArgument(new Reference('state'));
  } catch (InvalidArgumentException $e) {

    // Do nothing, Redirect module is not installed.
  }

  // Override the access_check.node.revision class with a new class.
  try {
    $definition = $container
      ->getDefinition('access_check.node.revision');
    $definition
      ->setClass('Drupal\\multiversion\\Access\\NodeRevisionAccessCheck');
  } catch (InvalidArgumentException $e) {

    // Do nothing, Node module is not installed.
  }
}