diff --git a/core/modules/update/src/UpdateRootFactory.php b/core/modules/update/src/UpdateRoot.php similarity index 82% rename from core/modules/update/src/UpdateRootFactory.php rename to core/modules/update/src/UpdateRoot.php index de9de58a89c9bc0611529084a7126d287dfbd36d..bfb21de2a8a33348970dc0baff75a1f8b5b2ac33 100644 --- a/core/modules/update/src/UpdateRootFactory.php +++ b/core/modules/update/src/UpdateRoot.php @@ -8,7 +8,7 @@ /** * Gets the root path used by the Update Manager to install or update projects. */ -class UpdateRootFactory { +class UpdateRoot { /** * The Drupal kernel. @@ -24,6 +24,13 @@ class UpdateRootFactory { */ protected $requestStack; + /** + * The update root. + * + * @var string + */ + protected $updateRoot; + /** * Constructs an UpdateRootFactory instance. * @@ -37,6 +44,16 @@ public function __construct(DrupalKernelInterface $drupal_kernel, RequestStack $ $this->requestStack = $request_stack; } + /** + * Sets the root path under which projects are installed or updated. + * + * @param string $update_root + * The update root. + */ + public function set(string $update_root): void { + $this->updateRoot = $update_root; + } + /** * Gets the root path under which projects are installed or updated. * @@ -45,7 +62,12 @@ public function __construct(DrupalKernelInterface $drupal_kernel, RequestStack $ * * @return string */ - public function get() { + public function __toString(): string { + // Return the $updateRoot when it is set. + if (isset($this->updateRoot)) { + return $this->updateRoot; + } + // Normally the Update Manager's root path is the same as the app root (the // directory in which the Drupal site is installed). $root_path = $this->drupalKernel->getAppRoot(); diff --git a/core/modules/update/tests/src/Functional/UpdateTestBase.php b/core/modules/update/tests/src/Functional/UpdateTestBase.php index 69d1f9f865b1d9ed973f6d59da7280ad358bd276..3ce5548317315f4e06c2d46611f23b9a2e6d3cc4 100644 --- a/core/modules/update/tests/src/Functional/UpdateTestBase.php +++ b/core/modules/update/tests/src/Functional/UpdateTestBase.php @@ -63,8 +63,7 @@ protected function setUp() { // test child site. $request = \Drupal::request(); $update_root = $this->container->get('update.root') . '/' . DrupalKernel::findSitePath($request); - $this->container->set('update.root', $update_root); - \Drupal::setContainer($this->container); + $this->container->get('update.root')->set($update_root); // Create the directories within the root path within which the Update // Manager will install projects. diff --git a/core/modules/update/update.services.yml b/core/modules/update/update.services.yml index df328443cd6129e00a2cb6fcc069dd76f5be4f71..d243fedcdbeb736c3b52a2b6ec7fe7c6fa0b32e7 100644 --- a/core/modules/update/update.services.yml +++ b/core/modules/update/update.services.yml @@ -14,11 +14,5 @@ services: class: Drupal\update\UpdateFetcher arguments: ['@config.factory', '@http_client', '@settings'] update.root: - class: SplString - factory: ['@update.root.factory', 'get'] - tags: - - { name: parameter_service } - update.root.factory: - class: Drupal\update\UpdateRootFactory + class: Drupal\update\UpdateRoot arguments: ['@kernel', '@request_stack'] - public: false