Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function alter(ContainerBuilder $container)
 {
     $definition = $container->getDefinition('asset.resolver');
     $argument = new Reference('cache.null');
     $definition->replaceArgument(5, $argument);
     $definition = $container->getDefinition('library.discovery.collector');
     $argument = new Reference('cache.null');
     $definition->replaceArgument(0, $argument);
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function alter(ContainerBuilder $container)
 {
     $definition = $container->getDefinition('language_manager');
     $definition->setClass('Drupal\\language\\ConfigurableLanguageManager')->addArgument(new Reference('config.factory'))->addArgument(new Reference('module_handler'))->addArgument(new Reference('language.config_factory_override'))->addArgument(new Reference('request_stack'));
     if ($default_language_values = $this->getDefaultLanguageValues()) {
         $container->setParameter('language.default_values', $default_language_values);
     }
     // For monolingual sites, we explicitly set the default language for the
     // language config override service as there is no language negotiation.
     if (!$this->isMultilingual()) {
         $container->getDefinition('language.config_factory_override')->addMethodCall('setLanguageFromDefault', array(new Reference('language.default')));
     }
 }
 /**
  * {@inheritdoc}
  */
 public function alter(ContainerBuilder $container)
 {
     if ($container->has('file.usage')) {
         // Override the class used for the file.usage service.
         $definition = $container->getDefinition('file.usage');
         $definition->setClass('Drupal\\service_provider_test\\TestFileUsage');
     }
 }
 /**
  * {@inheritdoc}
  */
 public function alter(ContainerBuilder $container)
 {
     $definition = $container->getDefinition('menu.active_trail');
     $definition->setClass('Drupal\\menu_trail_by_path\\MenuTrailByPathActiveTrail');
     $definition->addArgument(new Reference('language_manager'));
     $definition->addArgument(new Reference('path.current'));
     $definition->addArgument(new Reference('path.alias_manager'));
 }
 /**
  * {@inheritdoc}
  */
 public function alter(ContainerBuilder $container)
 {
     $definition = $container->getDefinition('country_manager');
     // Overrides country_manager class to add additional functionality.
     $definition->setClass('Drupal\\uc_country\\CountryManager');
     // Inject the entity_type.manager service, which is not available in
     // the core country_manager.
     $definition->addArgument(new Reference('entity_type.manager'));
 }
 /**
 * {@inheritdoc}
 */
 public function alter(ContainerBuilder $container)
 {
     $definition = $container->getDefinition('menu.link_tree');
     // Use custom CustomMenuLinkTree class instead of the
     // default MenuLinkTree class.
     $definition->setClass('Drupal\\custom\\CustomMenuLinkTree');
     // Provide an additional argument to the service to add
     // the current_route_match service.
     $definition->addArgument(new Reference('current_route_match'));
 }
 /**
  * {@inheritdoc}
  */
 public function alter(ContainerBuilder $container)
 {
     if ($container->has('file.usage')) {
         // Override the class used for the file.usage service.
         $definition = $container->getDefinition('file.usage');
         $definition->setClass('Drupal\\service_provider_test\\TestFileUsage');
     }
     if ($indicator = Settings::get('deployment_identifier')) {
         $container->setParameter('container_rebuild_indicator', $indicator);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function alter(ContainerBuilder $container)
 {
     // Ensure that URLs generated for the home and admin pages don't have
     // 'update.php' in them.
     $request = Request::createFromGlobals();
     $definition = $container->getDefinition('url_generator');
     $definition->addMethodCall('setBasePath', array(str_replace('/core', '', $request->getBasePath()) . '/'));
     // We need to set the script path to an empty string since the value
     // determined by \Drupal\Core\Routing\UrlGenerator::setRequest() is invalid
     // once '/core' has been removed from the base path.
     $definition->addMethodCall('setScriptPath', array(''));
 }
Exemplo n.º 9
0
 /**
  * @param \Drupal\Core\DependencyInjection\ContainerBuilder $container
  * @param $id
  * @param $title
  */
 protected function addLightbox(ContainerBuilder $container, $id, $title)
 {
     $definition = $container->getDefinition($id);
     $tags = $definition->getTags();
     foreach ($tags as $delta => &$tag) {
         if ($delta === 'render.main_content_renderer') {
             foreach ($tag as &$attribute) {
                 $attribute['ng_lightbox'] = $title;
             }
         }
     }
     $definition->setTags($tags);
 }
Exemplo n.º 10
0
 /**
  * Add the on demand rebuild route provider service.
  *
  * @param \Drupal\Core\DependencyInjection\ContainerBuilder $container
  */
 public static function addRouteProvider(ContainerBuilder $container)
 {
     foreach (['router.route_provider' => 'RouteProvider'] as $original_id => $class) {
         // While $container->get() does a recursive resolve, getDefinition() does
         // not, so do it ourselves.
         for ($id = $original_id; $container->hasAlias($id); $id = (string) $container->getAlias($id)) {
         }
         $definition = $container->getDefinition($id);
         $definition->clearTag('needs_destruction');
         $container->setDefinition("simpletest.{$original_id}", $definition);
         $container->setDefinition($id, new Definition('Drupal\\simpletest\\' . $class));
     }
 }
Exemplo n.º 11
0
    public function testParseDefinitionsWithProvider()
    {
        $yml = <<<YAML
services:
  example_service:
    class: \\Drupal\\Core\\ExampleClass
YAML;
        vfsStream::setup('drupal', NULL, ['modules/example/example.yml' => $yml]);
        $builder = new ContainerBuilder();
        $yaml_file_loader = new YamlFileLoader($builder);
        $yaml_file_loader->load('vfs://drupal/modules/example/example.yml');
        $this->assertEquals(['_provider' => [['provider' => 'example']]], $builder->getDefinition('example_service')->getTags());
    }
Exemplo n.º 12
0
 /**
  * {@inheritdoc}
  */
 public function alter(ContainerBuilder $container)
 {
     if ($container->has('config.factory')) {
         // The configuration factory depends on the cache factory, but that
         // depends on the 'cache_default_bin_backends' parameter that has not yet
         // been set by \Drupal\Core\Cache\ListCacheBinsPass::process() at this
         // point.
         $parameter_name = 'cache_default_bin_backends';
         if (!$container->hasParameter($parameter_name)) {
             $container->setParameter($parameter_name, []);
         }
         /** @var \Drupal\Core\Config\ConfigFactoryInterface $config_factory */
         $config_factory = $container->get('config.factory');
         $config = $config_factory->get('libraries.settings');
         if (!$config->isNew()) {
             // Set the local definition path.
             $container->getDefinition('libraries.definition.discovery.local')->replaceArgument(1, $config->get('definition.local.path'));
             // Set the remote definition URL. Note that this is set even if
             // the remote discovery is not enabled below in case the
             // 'libraries.definition.discovery.remote' service is used explicitly.
             $container->getDefinition('libraries.definition.discovery.remote')->replaceArgument(2, $config->get('definition.remote.url'));
             // Because it is less convenient to remove a method call than to add
             // one, the remote discovery is not registered in libraries.services.yml
             // and instead added here, even though the 'definition.remote.enable'
             // configuration value is TRUE by default.
             if ($config->get('definition.remote.enable')) {
                 // Add the remote discovery to the list of chained discoveries.
                 $container->getDefinition('libraries.definition.discovery')->addMethodCall('addDiscovery', [new Reference('libraries.definition.discovery.remote')]);
             }
         }
         // At this point the event dispatcher has not yet been populated with
         // event subscribers by RegisterEventSubscribersPass::process() but has
         // already bin injected in the configuration factory. Reset those services
         // accordingly.
         $container->set('event_dispatcher', NULL);
         $container->set('config.factory', NULL);
     }
 }
 public function alter(ContainerBuilder $container)
 {
     // Override the password_migrate class with a new class.
     try {
         $definition = $container->getDefinition('password_migrate');
         $definition->setClass('Drupal\\multiversion\\MigratePassword');
     } catch (InvalidArgumentException $e) {
         // Do nothing, migrate module is not installed.
     }
     $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.
     }
 }
 /**
  * {@inheritdoc}
  */
 public function alter(ContainerBuilder $container)
 {
     // Disable configuration overrides.
     // ConfigFactory would to try to load language overrides and InstallStorage
     // throws an exception upon trying to load a non-existing file.
     $container->get('config.factory')->setOverrideState(FALSE);
     // No service may persist when the early installer kernel is rebooted into
     // the production environment.
     // @todo The DrupalKernel reboot performed by drupal_install_system() is
     //   actually not a "regular" reboot (like ModuleHandler::install()), so
     //   services are not actually persisted.
     foreach ($container->findTaggedServiceIds('persist') as $id => $tags) {
         $definition = $container->getDefinition($id);
         $definition->clearTag('persist');
     }
 }
Exemplo n.º 15
0
 /**
  * {@inheritdoc}
  */
 public function alter(ContainerBuilder $container)
 {
     // Disable Twig cache (php storage does not exist yet).
     $twig_config = $container->getParameter('twig.config');
     $twig_config['cache'] = FALSE;
     $container->setParameter('twig.config', $twig_config);
     // No service may persist when the early installer kernel is rebooted into
     // the production environment.
     // @todo The DrupalKernel reboot performed by drupal_install_system() is
     //   actually not a "regular" reboot (like ModuleHandler::install()), so
     //   services are not actually persisted.
     foreach ($container->findTaggedServiceIds('persist') as $id => $tags) {
         $definition = $container->getDefinition($id);
         $definition->clearTag('persist');
     }
 }
 /**
  * {@inheritdoc}
  */
 public function alter(ContainerBuilder $container)
 {
     $modules = $container->getParameter('container.modules');
     // Alter the views.executable service only if Views module is enabled.
     if (isset($modules['views'])) {
         $container->getDefinition('views.executable')->setClass('Drupal\\webprofiler\\Views\\ViewExecutableFactoryWrapper');
     }
     // Replace the regular form_builder service with a traceable one.
     $container->getDefinition('form_builder')->setClass('Drupal\\webprofiler\\Form\\FormBuilderWrapper');
     // Replace the regular plugin.manager.mail service with a traceable one.
     $container->getDefinition('plugin.manager.mail')->setClass('Drupal\\webprofiler\\Mail\\MailManagerWrapper')->addMethodCall('setDataCollector', [new Reference('webprofiler.mail')]);
     // Replace the regular access_manager service with a traceable one.
     $container->getDefinition('access_manager')->setClass('Drupal\\webprofiler\\Access\\AccessManagerWrapper')->addMethodCall('setDataCollector', [new Reference('webprofiler.request')]);
     // Replace the regular theme.negotiator service with a traceable one.
     $container->getDefinition('theme.negotiator')->setClass('Drupal\\webprofiler\\Theme\\ThemeNegotiatorWrapper');
     // Replace the regular config.factory service with a traceable one.
     $container->getDefinition('config.factory')->setClass('Drupal\\webprofiler\\Config\\ConfigFactoryWrapper')->addMethodCall('setDataCollector', [new Reference('webprofiler.config')]);
     // Replace the regular string_translation service with a traceable one.
     $container->getDefinition('string_translation')->setClass('Drupal\\webprofiler\\StringTranslation\\TranslationManagerWrapper');
 }
Exemplo n.º 17
0
 /**
  * Registers test-specific services.
  *
  * Extend this method in your test to register additional services. This
  * method is called whenever the kernel is rebuilt.
  *
  * @param \Drupal\Core\DependencyInjection\ContainerBuilder $container
  *   The service container to enhance.
  *
  * @see \Drupal\Tests\KernelTestBase::bootKernel()
  */
 public function register(ContainerBuilder $container)
 {
     // Keep the container object around for tests.
     $this->container = $container;
     $container->register('flood', 'Drupal\\Core\\Flood\\MemoryBackend')->addArgument(new Reference('request_stack'));
     $container->register('lock', 'Drupal\\Core\\Lock\\NullLockBackend');
     $container->register('cache_factory', 'Drupal\\Core\\Cache\\MemoryBackendFactory');
     $container->register('keyvalue.memory', 'Drupal\\Core\\KeyValueStore\\KeyValueMemoryFactory')->addTag('persist');
     $container->setAlias('keyvalue', 'keyvalue.memory');
     // Set the default language on the minimal container.
     $container->setParameter('language.default_values', Language::$defaultValues);
     if ($this->strictConfigSchema) {
         $container->register('simpletest.config_schema_checker', 'Drupal\\Core\\Config\\Testing\\ConfigSchemaChecker')->addArgument(new Reference('config.typed'))->addArgument($this->getConfigSchemaExclusions())->addTag('event_subscriber');
     }
     if ($container->hasDefinition('path_processor_alias')) {
         // Prevent the alias-based path processor, which requires a url_alias db
         // table, from being registered to the path processor manager. We do this
         // by removing the tags that the compiler pass looks for. This means the
         // url generator can safely be used within tests.
         $container->getDefinition('path_processor_alias')->clearTag('path_processor_inbound')->clearTag('path_processor_outbound');
     }
     if ($container->hasDefinition('password')) {
         $container->getDefinition('password')->setArguments(array(1));
     }
     TestServiceProvider::addRouteProvider($container);
 }
Exemplo n.º 18
0
 public function alter(ContainerBuilder $container)
 {
     $urlGeneratorDefinition = $container->getDefinition('url_generator');
     $urlGeneratorDefinition->replaceArgument(0, new Reference('purl.url_generator'));
 }
Exemplo n.º 19
0
  /**
   * Registers test-specific services.
   *
   * Extend this method in your test to register additional services. This
   * method is called whenever the kernel is rebuilt.
   *
   * @param \Drupal\Core\DependencyInjection\ContainerBuilder $container
   *   The service container to enhance.
   *
   * @see \Drupal\Tests\KernelTestBase::bootKernel()
   */
  public function register(ContainerBuilder $container) {
    // Keep the container object around for tests.
    $this->container = $container;

    $container
      ->register('flood', 'Drupal\Core\Flood\MemoryBackend')
      ->addArgument(new Reference('request_stack'));
    $container
      ->register('lock', 'Drupal\Core\Lock\NullLockBackend');
    $container
      ->register('cache_factory', 'Drupal\Core\Cache\MemoryBackendFactory');
    $container
      ->register('keyvalue.memory', 'Drupal\Core\KeyValueStore\KeyValueMemoryFactory')
      // Must persist container rebuilds, or all data would vanish otherwise.
      ->addTag('persist');
    $container
      ->setAlias('keyvalue', 'keyvalue.memory');

    if ($this->strictConfigSchema) {
      $container
        ->register('simpletest.config_schema_checker', 'Drupal\Core\Config\Testing\ConfigSchemaChecker')
        ->addArgument(new Reference('config.typed'))
        ->addTag('event_subscriber');
    }

    if ($container->hasDefinition('path_processor_alias')) {
      // Prevent the alias-based path processor, which requires a url_alias db
      // table, from being registered to the path processor manager. We do this
      // by removing the tags that the compiler pass looks for. This means the
      // url generator can safely be used within tests.
      $container->getDefinition('path_processor_alias')
        ->clearTag('path_processor_inbound')
        ->clearTag('path_processor_outbound');
    }

    if ($container->hasDefinition('password')) {
      $container->getDefinition('password')
        ->setArguments(array(1));
    }
  }
Exemplo n.º 20
0
 /**
  * {@inheritdoc}
  */
 public function alter(ContainerBuilder $container)
 {
     // Overrides the core condition plugin manager service with our own.
     $definition = $container->getDefinition('plugin.manager.condition');
     $definition->setClass(ConditionManager::class);
 }
 /**
  * {@inheritdoc}
  */
 public function alter(ContainerBuilder $container)
 {
     $definition = $container->getDefinition('menu.active_trail');
     $definition->setClass('Drupal\\menu_trail_by_path\\MenuTrailByPathActiveTrail');
 }
Exemplo n.º 22
0
 /**
  * {@inheritdoc}
  */
 public function alter(ContainerBuilder $container)
 {
     $definition = $container->getDefinition('token');
     $definition->setClass('\\Drupal\\token\\Token');
 }
Exemplo n.º 23
0
 /**
  * {@inheritdoc}
  */
 public function alter(ContainerBuilder $container)
 {
     $container->setDefinition('password_original', $container->getDefinition('password'));
     $container->setDefinition('password', $container->getDefinition('password_migrate'));
 }
Exemplo n.º 24
0
 /**
  * {@inheritdoc}
  */
 public function alter(ContainerBuilder $container)
 {
     // Change class of menu.link_tree service.
     $definition = $container->getDefinition('menu.link_tree');
     $definition->setClass('Drupal\\sitemap\\Menu\\MenuLinkTree');
 }
Exemplo n.º 25
0
 /**
  * {@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', ['hal_json', ['application/hal+json']]);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function alter(ContainerBuilder $container)
 {
     $container->getDefinition('form_error_handler')->setClass(FormErrorHandler::class)->setArguments([new Reference('string_translation'), new Reference('link_generator'), new Reference('renderer')]);
 }
Exemplo n.º 27
0
 /**
  * Sets up the base service container for this test.
  *
  * Extend this method in your test to register additional service overrides
  * that need to persist a DrupalKernel reboot. This method is called whenever
  * the kernel is rebuilt.
  *
  * @see \Drupal\simpletest\KernelTestBase::setUp()
  * @see \Drupal\simpletest\KernelTestBase::enableModules()
  * @see \Drupal\simpletest\KernelTestBase::disableModules()
  */
 public function containerBuild(ContainerBuilder $container)
 {
     // Keep the container object around for tests.
     $this->container = $container;
     // Set the default language on the minimal container.
     $this->container->setParameter('language.default_values', $this->defaultLanguageData());
     $container->register('lock', 'Drupal\\Core\\Lock\\NullLockBackend');
     $container->register('cache_factory', 'Drupal\\Core\\Cache\\MemoryBackendFactory');
     $container->register('config.storage', 'Drupal\\Core\\Config\\DatabaseStorage')->addArgument(Database::getConnection())->addArgument('config');
     if ($this->strictConfigSchema) {
         $container->register('simpletest.config_schema_checker', 'Drupal\\Core\\Config\\Testing\\ConfigSchemaChecker')->addArgument(new Reference('config.typed'))->addArgument($this->getConfigSchemaExclusions())->addTag('event_subscriber');
     }
     $keyvalue_options = $container->getParameter('factory.keyvalue') ?: array();
     $keyvalue_options['default'] = 'keyvalue.memory';
     $container->setParameter('factory.keyvalue', $keyvalue_options);
     $container->set('keyvalue.memory', $this->keyValueFactory);
     if (!$container->has('keyvalue')) {
         // TestBase::setUp puts a completely empty container in
         // $this->container which is somewhat the mirror of the empty
         // environment being set up. Unit tests need not to waste time with
         // getting a container set up for them. Drupal Unit Tests might just get
         // away with a simple container holding the absolute bare minimum. When
         // a kernel is overridden then there's no need to re-register the keyvalue
         // service but when a test is happy with the superminimal container put
         // together here, it still might a keyvalue storage for anything using
         // \Drupal::state() -- that's why a memory service was added in the first
         // place.
         $container->register('settings', 'Drupal\\Core\\Site\\Settings')->setFactoryClass('Drupal\\Core\\Site\\Settings')->setFactoryMethod('getInstance');
         $container->register('keyvalue', 'Drupal\\Core\\KeyValueStore\\KeyValueFactory')->addArgument(new Reference('service_container'))->addArgument(new Parameter('factory.keyvalue'));
         $container->register('state', 'Drupal\\Core\\State\\State')->addArgument(new Reference('keyvalue'));
     }
     if ($container->hasDefinition('path_processor_alias')) {
         // Prevent the alias-based path processor, which requires a url_alias db
         // table, from being registered to the path processor manager. We do this
         // by removing the tags that the compiler pass looks for. This means the
         // url generator can safely be used within tests.
         $definition = $container->getDefinition('path_processor_alias');
         $definition->clearTag('path_processor_inbound')->clearTag('path_processor_outbound');
     }
     if ($container->hasDefinition('password')) {
         $container->getDefinition('password')->setArguments(array(1));
     }
     // Register the stream wrapper manager.
     $container->register('stream_wrapper_manager', 'Drupal\\Core\\StreamWrapper\\StreamWrapperManager')->addArgument(new Reference('module_handler'))->addMethodCall('setContainer', array(new Reference('service_container')));
     $request = Request::create('/');
     $container->get('request_stack')->push($request);
 }
 /**
  * {@inheritdoc}
  */
 public function alter(ContainerBuilder $container)
 {
     // Override the config.installer class with a new class.
     $definition = $container->getDefinition('config.installer');
     $definition->setClass('Drupal\\features\\FeaturesConfigInstaller');
 }
Exemplo n.º 29
0
 /**
  * Alters the UUID service to use the most efficient method available.
  *
  * @param \Drupal\Core\DependencyInjection\ContainerBuilder $container
  *   The container builder.
  */
 public function alter(ContainerBuilder $container)
 {
     $uuid_service = $container->getDefinition('uuid');
     // Debian/Ubuntu uses the (broken) OSSP extension as their UUID
     // implementation. The OSSP implementation is not compatible with the
     // PECL functions.
     if (function_exists('uuid_create') && !function_exists('uuid_make')) {
         $uuid_service->setClass('Drupal\\Component\\Uuid\\Pecl');
     } elseif (function_exists('com_create_guid')) {
         $uuid_service->setClass('Drupal\\Component\\Uuid\\Com');
     }
 }
Exemplo n.º 30
0
 /**
  * {@inheritdoc}
  */
 public function alter(ContainerBuilder $container)
 {
     if ($container->has('http_middleware.negotiation')) {
         $container->getDefinition('http_middleware.negotiation')->addMethodCall('registerFormat', ['hal_json', ['application/hal+json']]);
     }
 }