public function BackendCompilerPass::process

public BackendCompilerPass::process(ContainerBuilder $container)

You can modify the container here before it is dumped to PHP code.

Parameters

ContainerBuilder $container:

Overrides CompilerPassInterface::process

File

core/lib/Drupal/Core/DependencyInjection/Compiler/BackendCompilerPass.php, line 39

Class

BackendCompilerPass
Defines a compiler pass to allow automatic override per backend.

Namespace

Drupal\Core\DependencyInjection\Compiler

Code

public function process(ContainerBuilder $container) {
  if ($container->hasParameter('default_backend')) {
    $default_backend = $container->getParameter('default_backend');
    // Opt out from the default backend.
    if (!$default_backend) {
      return;
    }
  }
  else {
    try {
      $default_backend = $container->get('database')->driver();
      $container->set('database', NULL);
    }
    catch (\Exception $e) {
      // If Drupal is not installed or a test doesn't define database there
      // is nothing to override.
      return;
    }
  }


  foreach ($container->findTaggedServiceIds('backend_overridable') as $id => $attributes) {
    // If the service is already an alias it is not the original backend, so
    // we don't want to fallback to other storages any longer.
    if ($container->hasAlias($id)) {
      continue;
    }
    if ($container->hasDefinition("$default_backend.$id") || $container->hasAlias("$default_backend.$id")) {
      $container->setAlias($id, new Alias("$default_backend.$id"));
    }
  }
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!DependencyInjection!Compiler!BackendCompilerPass.php/function/BackendCompilerPass::process/8.1.x