diff --cc core/core.services.yml index 50281cd,1c898cb..0000000 --- a/core/core.services.yml +++ b/core/core.services.yml @@@ -288,10 -287,13 +288,13 @@@ services arguments: ['@container.namespaces', '@cache.discovery', '@module_handler'] module_handler: class: Drupal\Core\Extension\ModuleHandler - arguments: ['@app.root', '%container.modules%', '@kernel', '@cache.bootstrap'] - arguments: ['%container.modules%', '@cache.bootstrap'] ++ arguments: ['@app.root', '%container.modules%', '@cache.bootstrap'] + module_installer: + class: Drupal\Core\Extension\ModuleInstaller - arguments: ['@module_handler', '@kernel'] ++ arguments: ['@app.root', '@module_handler', '@kernel'] theme_handler: class: Drupal\Core\Extension\ThemeHandler - arguments: ['@config.factory', '@module_handler', '@state', '@info_parser', '@logger.channel.default', '@asset.css.collection_optimizer', '@config.installer', '@config.manager', '@router.builder_indicator'] + arguments: ['@app.root', '@config.factory', '@module_handler', '@state', '@info_parser', '@logger.channel.default', '@asset.css.collection_optimizer', '@config.installer', '@config.manager', '@router.builder_indicator'] entity.manager: class: Drupal\Core\Entity\EntityManager arguments: ['@container.namespaces', '@module_handler', '@cache.discovery', '@language_manager', '@string_translation', '@class_resolver', '@typed_data_manager', '@entity.definitions.installed', '@event_dispatcher'] diff --cc core/lib/Drupal/Core/Extension/ModuleHandler.php index 12d2805,2ffebf3..0000000 --- a/core/lib/Drupal/Core/Extension/ModuleHandler.php +++ b/core/lib/Drupal/Core/Extension/ModuleHandler.php @@@ -108,21 -92,19 +101,18 @@@ class ModuleHandler implements ModuleHa * An associative array whose keys are the names of installed modules and * whose values are Extension class parameters. This is normally the * %container.modules% parameter being set up by DrupalKernel. -- * @param \Drupal\Core\DrupalKernelInterface $kernel -- * The drupal kernel. * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend * Cache backend for storing module hook implementation information. * * @see \Drupal\Core\DrupalKernel * @see \Drupal\Core\CoreServiceProvider */ - public function __construct($root, array $module_list = array(), DrupalKernelInterface $kernel, CacheBackendInterface $cache_backend) { - public function __construct(array $module_list = array(), CacheBackendInterface $cache_backend) { ++ public function __construct($root, array $module_list = array(), CacheBackendInterface $cache_backend) { + $this->root = $root; $this->moduleList = array(); foreach ($module_list as $name => $module) { - $this->moduleList[$name] = new Extension($module['type'], $module['pathname'], $module['filename']); + $this->moduleList[$name] = new Extension($this->root, $module['type'], $module['pathname'], $module['filename']); } - $this->kernel = $kernel; $this->cacheBackend = $cache_backend; } diff --cc core/lib/Drupal/Core/Installer/Form/SiteConfigureForm.php index 05c9c23,7aab4a7..0000000 --- a/core/lib/Drupal/Core/Installer/Form/SiteConfigureForm.php +++ b/core/lib/Drupal/Core/Installer/Form/SiteConfigureForm.php @@@ -69,11 -60,10 +69,11 @@@ class SiteConfigureForm extends FormBas * @param \Drupal\Core\Locale\CountryManagerInterface $country_manager * The country manager. */ - public function __construct($root, UserStorageInterface $user_storage, StateInterface $state, ModuleHandlerInterface $module_handler, CountryManagerInterface $country_manager) { - public function __construct(UserStorageInterface $user_storage, StateInterface $state, ModuleInstallerInterface $module_installer, CountryManagerInterface $country_manager) { ++ public function __construct($root, UserStorageInterface $user_storage, StateInterface $state, ModuleInstallerInterface $module_installer, CountryManagerInterface $country_manager) { + $this->root = $root; $this->userStorage = $user_storage; $this->state = $state; - $this->moduleHandler = $module_handler; + $this->moduleInstaller = $module_installer; $this->countryManager = $country_manager; } @@@ -82,10 -72,9 +82,10 @@@ */ public static function create(ContainerInterface $container) { return new static( + $container->get('app.root'), $container->get('entity.manager')->getStorage('user'), $container->get('state'), - $container->get('module_handler'), + $container->get('module_installer'), $container->get('country_manager') ); } diff --cc core/modules/system/src/Tests/Plugin/PluginTestBase.php index 618c4ef,94e6ad8..0000000 --- a/core/modules/system/src/Tests/Plugin/PluginTestBase.php +++ b/core/modules/system/src/Tests/Plugin/PluginTestBase.php @@@ -47,7 -47,7 +47,7 @@@ abstract class PluginTestBase extends K // as derivatives and ReflectionFactory. $this->testPluginManager = new TestPluginManager(); $this->mockBlockManager = new MockBlockManager(); - $module_handler = new ModuleHandler(\Drupal::root(), array(), $this->container->get('kernel'), new MemoryBackend('plugin')); - $module_handler = new ModuleHandler(array(), new MemoryBackend('plugin'), $this->container->get('event_dispatcher')); ++ $module_handler = new ModuleHandler(\Drupal::root(), array(), new MemoryBackend('plugin'), $this->container->get('event_dispatcher')); $this->defaultsTestPluginManager = new DefaultsTestPluginManager($module_handler); // The expected plugin definitions within each manager. Several tests assert diff --cc core/modules/taxonomy/src/Tests/VocabularyCrudTest.php index f265ec2,ffe5213..0000000 --- a/core/modules/taxonomy/src/Tests/VocabularyCrudTest.php +++ b/core/modules/taxonomy/src/Tests/VocabularyCrudTest.php @@@ -193,9 -193,9 +193,9 @@@ class VocabularyCrudTest extends Taxono ); entity_create('field_config', $field_definition)->save(); - require_once DRUPAL_ROOT . '/core/includes/install.inc'; + require_once \Drupal::root() . '/core/includes/install.inc'; - $this->container->get('module_handler')->uninstall(array('taxonomy')); - \Drupal::moduleHandler()->install(array('taxonomy')); + $this->container->get('module_installer')->uninstall(array('taxonomy')); + $this->container->get('module_installer')->install(array('taxonomy')); // Now create a vocabulary with the same name. All fields // connected to this vocabulary name should have been removed when the diff --cc core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php index fe5b6e0,9e8b07e..0000000 --- a/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php +++ b/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php @@@ -44,12 -37,8 +37,10 @@@ class ModuleHandlerTest extends UnitTes * @covers ::__construct */ protected function setUp() { + parent::setUp(); + - $this->kernel = $this->getMock('Drupal\Core\DrupalKernelInterface'); - $this->cacheBackend = $this->getMock('Drupal\Core\Cache\CacheBackendInterface'); - $this->moduleHandler = new ModuleHandler(array( + $this->moduleHandler = new ModuleHandler($this->root, array( 'module_handler_test' => array( 'type' => 'module', 'pathname' => 'core/tests/Drupal/Tests/Core/Extension/modules/module_handler_test/module_handler_test.info.yml', @@@ -175,7 -163,7 +166,7 @@@ public function testSetModuleList() { $module_handler = $this->getMockBuilder('Drupal\Core\Extension\ModuleHandler') ->setConstructorArgs(array( - $this->root, array(), $this->kernel, $this->cacheBackend - array(), $this->cacheBackend ++ $this->root, array(), $this->cacheBackend )) ->setMethods(array('resetImplementations')) ->getMock(); @@@ -203,7 -191,7 +194,7 @@@ $module_handler = $this->getMockBuilder('Drupal\Core\Extension\ModuleHandler') ->setConstructorArgs(array( - $this->root, array(), $this->kernel, $this->cacheBackend - array(), $this->cacheBackend ++ $this->root, array(), $this->cacheBackend )) ->setMethods(array('resetImplementations')) ->getMock(); @@@ -225,7 -213,7 +216,7 @@@ $module_handler = $this->getMockBuilder('Drupal\Core\Extension\ModuleHandler') ->setConstructorArgs(array( - $this->root, array(), $this->kernel, $this->cacheBackend - array(), $this->cacheBackend ++ $this->root, array(), $this->cacheBackend )) ->setMethods(array('resetImplementations')) ->getMock(); diff --git a/core/lib/Drupal/Core/Config/ConfigImporter.php b/core/lib/Drupal/Core/Config/ConfigImporter.php index 007282e..82487e7 100644 --- a/core/lib/Drupal/Core/Config/ConfigImporter.php +++ b/core/lib/Drupal/Core/Config/ConfigImporter.php @@ -7,6 +7,7 @@ namespace Drupal\Core\Config; +use Drupal\Core\DependencyInjection\DependencyReinjectTrait; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Extension\ModuleInstallerInterface; use Drupal\Core\Extension\ThemeHandlerInterface; @@ -41,6 +42,7 @@ class ConfigImporter { use StringTranslationTrait; use DependencySerializationTrait; + use DependencyReinjectTrait; /** * The name used to identify the lock. @@ -1010,21 +1012,5 @@ public function alreadyImporting() { return !$this->lock->lockMayBeAvailable(static::LOCK_NAME); } - /** - * Gets all the service dependencies from \Drupal. - * - * Since the ConfigImporter handles module installation the kernel and the - * container can be rebuilt and altered during processing. It is necessary to - * keep the services used by the importer in sync. - */ - protected function reInjectMe() { - $this->_serviceIds = array(); - $vars = get_object_vars($this); - foreach ($vars as $key => $value) { - if (is_object($value) && isset($value->_serviceId)) { - $this->$key = \Drupal::service($value->_serviceId); - } - } - } } diff --git a/core/lib/Drupal/Core/DependencyInjection/DependencyReinjectTrait.php b/core/lib/Drupal/Core/DependencyInjection/DependencyReinjectTrait.php index d99c30d..7098da4 100644 --- a/core/lib/Drupal/Core/DependencyInjection/DependencyReinjectTrait.php +++ b/core/lib/Drupal/Core/DependencyInjection/DependencyReinjectTrait.php @@ -7,7 +7,23 @@ namespace Drupal\Core\DependencyInjection; -class DependencyReinjectTrait { +/** + * Reinjects all dependencies of an object, by fetching it from \Drupal. + */ +trait DependencyReinjectTrait { + + /** + * Gets all the service dependencies from \Drupal. + */ + protected function reInjectMe() { + $this->_serviceIds = array(); + $vars = get_object_vars($this); + foreach ($vars as $key => $value) { + if (is_object($value) && isset($value->_serviceId)) { + $this->$key = \Drupal::service($value->_serviceId); + } + } + } } diff --git a/core/lib/Drupal/Core/Extension/ModuleInstaller.php b/core/lib/Drupal/Core/Extension/ModuleInstaller.php index f5e3c2d..6f470f1 100644 --- a/core/lib/Drupal/Core/Extension/ModuleInstaller.php +++ b/core/lib/Drupal/Core/Extension/ModuleInstaller.php @@ -9,6 +9,7 @@ use Drupal\Component\Serialization\Yaml; use Drupal\Core\Cache\CacheBackendInterface; +use Drupal\Core\DependencyInjection\DependencyReinjectTrait; use Drupal\Core\DrupalKernelInterface; /** @@ -19,6 +20,8 @@ */ class ModuleInstaller implements ModuleInstallerInterface { + use DependencyReinjectTrait; + /** * The module handler. * @@ -27,10 +30,29 @@ class ModuleInstaller implements ModuleInstallerInterface { protected $moduleHandler; /** + * The app root. + * + * @var string + */ + protected $root; + + /** + * @var \Drupal\Core\DrupalKernelInterface + */ + protected $kernel; + + /** + * Constructs a new ModuleInstaller. + * + * @param string $root + * The app root. * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * The module handler. + * @param \Drupal\Core\DrupalKernelInterface $kernel + * The drupal kernel. */ - public function __construct(ModuleHandlerInterface $module_handler, DrupalKernelInterface $kernel) { + public function __construct($root, ModuleHandlerInterface $module_handler, DrupalKernelInterface $kernel) { + $this->root = $root; $this->moduleHandler = $module_handler; $this->kernel = $kernel; } @@ -83,7 +105,7 @@ public function install(array $module_list, $enable_dependencies = TRUE) { } // Required for module installation checks. - include_once DRUPAL_ROOT . '/core/includes/install.inc'; + include_once $this->root . '/core/includes/install.inc'; /** @var \Drupal\Core\Config\ConfigInstaller $config_installer */ $config_installer = \Drupal::service('config.installer'); @@ -399,7 +421,7 @@ protected function removeCacheBins($module) { // be extremely rare. if ($tag['name'] == 'cache.bin' && isset($definition['factory_service']) && isset($definition['factory_method']) && !empty($definition['arguments'])) { try { - $factory = \Drupal::service($definition['factory_service']); + $factory = $this->kernel->getContainer()->get($definition['factory_service']); if (method_exists($factory, $definition['factory_method'])) { $backend = call_user_func_array(array($factory, $definition['factory_method']), $definition['arguments']); if ($backend instanceof CacheBackendInterface) { @@ -430,10 +452,10 @@ protected function updateKernel($module_filenames) { // %container.modules% parameter, which is passed to a fresh ModuleHandler // instance upon first retrieval. $this->kernel->updateModules($module_filenames, $module_filenames); + // After rebuilding the container we need to update the injected // dependencies. - $container = $this->kernel->getContainer(); - $this->moduleHandler = $container->get('module_handler'); + $this->reInjectMe(); } }