class WorkspacesServiceProvider

Same name in other branches
  1. 9 core/modules/workspaces/src/WorkspacesServiceProvider.php \Drupal\workspaces\WorkspacesServiceProvider
  2. 8.9.x core/modules/workspaces/src/WorkspacesServiceProvider.php \Drupal\workspaces\WorkspacesServiceProvider
  3. 11.x core/modules/workspaces/src/WorkspacesServiceProvider.php \Drupal\workspaces\WorkspacesServiceProvider

Defines a service provider for the Workspaces module.

Hierarchy

Expanded class hierarchy of WorkspacesServiceProvider

File

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

Namespace

Drupal\workspaces
View source
class WorkspacesServiceProvider extends ServiceProviderBase {
    
    /**
     * {@inheritdoc}
     */
    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);
        // Decorate the 'path_alias.manager' service.
        if ($container->hasDefinition('path_alias.manager')) {
            $container->register('workspaces.path_alias.manager', WorkspacesAliasManager::class)
                ->setPublic(FALSE)
                ->setDecoratedService('path_alias.manager', NULL, 50)
                ->addArgument(new Reference('workspaces.path_alias.manager.inner'))
                ->addArgument(new Reference('workspaces.manager'));
        }
        // 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');
                }
            }
        }
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
ServiceProviderBase::register public function Registers services to the container. Overrides ServiceProviderInterface::register 1
WorkspacesServiceProvider::alter public function Modifies existing service definitions. Overrides ServiceProviderBase::alter

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.