You are here

public function WorkspacesServiceProvider::alter in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/workspaces/src/WorkspacesServiceProvider.php \Drupal\workspaces\WorkspacesServiceProvider::alter()
  2. 9 core/modules/workspaces/src/WorkspacesServiceProvider.php \Drupal\workspaces\WorkspacesServiceProvider::alter()

File

core/modules/workspaces/src/WorkspacesServiceProvider.php, line 18

Class

WorkspacesServiceProvider
Defines a service provider for the Workspaces module.

Namespace

Drupal\workspaces

Code

public function alter(ContainerBuilder $container) {

  // Add the 'workspace' cache context as required.
  $renderer_config = $container
    ->getParameter('renderer.config');
  $renderer_config['required_cache_contexts'][] = 'workspace';
  $container
    ->setParameter('renderer.config', $renderer_config);

  // Replace the class of the 'path_alias.repository' service.
  if ($container
    ->hasDefinition('path_alias.repository')) {
    $definition = $container
      ->getDefinition('path_alias.repository');
    if (!$definition
      ->isDeprecated()) {
      $definition
        ->setClass(WorkspacesAliasRepository::class)
        ->addMethodCall('setWorkspacesManager', [
        new Reference('workspaces.manager'),
      ]);
    }
  }

  // Ensure that there's no active workspace while running database updates by
  // removing the relevant tag from all workspace negotiator services.
  if ($container
    ->get('kernel') instanceof UpdateKernel) {
    foreach ($container
      ->getDefinitions() as $definition) {
      if ($definition
        ->hasTag('workspace_negotiator')) {
        $definition
          ->clearTag('workspace_negotiator');
      }
    }
  }
}