Skip to content
Snippets Groups Projects
Commit 8165415c authored by catch's avatar catch
Browse files

Issue #3035274 by claudiu.cristea, naveenvalecha, Berdir: Deprecate...

Issue #3035274 by claudiu.cristea, naveenvalecha, Berdir: Deprecate drupal_classloader_register() & system_register()
parent 6cbdee92
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -811,8 +811,21 @@ function drupal_get_profile() {
* The namespace component to register; e.g., 'node'.
* @param string $path
* The relative path to the Drupal component in the filesystem.
*
* @deprecated in Drupal 8.8.0, will be removed before Drupal 9.0.0. Use the
* class loader as injected service instance to register the namespace:
* @code
* $this->classLoader->addPsr4('Drupal\\' . $name . '\\', \Drupal::root() . '/' . $path . '/src');
* @endcode
* or the following code if the service cannot be injected:
* @code
* \Drupal::service('class_loader')->addPsr4('Drupal\\' . $name . '\\', \Drupal::root() . '/' . $path . '/src');
* @endcode
*
* @see https://www.drupal.org/node/3035275
*/
function drupal_classloader_register($name, $path) {
@trigger_error('drupal_classloader_register() is deprecated in Drupal 8.8.0 and will be removed before Drupal 9.0.0. Use the method ::addPsr4() of the class_loader service to register the namespace. See https://www.drupal.org/node/3035275.', E_USER_DEPRECATED);
$loader = \Drupal::service('class_loader');
$loader->addPsr4('Drupal\\' . $name . '\\', \Drupal::root() . '/' . $path . '/src');
}
......
......@@ -986,7 +986,7 @@ function drupal_check_profile($profile) {
require_once $install_file;
}
drupal_classloader_register($module, $module_path);
\Drupal::service('class_loader')->addPsr4('Drupal\\' . $module . '\\', \Drupal::root() . "/$module_path/src");
if (function_exists($function)) {
$requirements = array_merge($requirements, $function('install'));
......
......@@ -69,10 +69,18 @@ function system_list_reset() {
* @param string $uri
* The relative URI of the primary extension file; e.g.,
* 'core/modules/node/node.module'.
*
* @deprecated in Drupal 8.8.0 and will be removed before Drupal 9.0.0. There is
* no replacement for this function. Use the following sequence of code to
* achieve the same functionality:
* @code
* $path = \Drupal::service("extension.list.$type")->getPath($name);
* \Drupal::service('class_loader')->addPsr4('Drupal\\' . $name . '\\', \Drupal::root() . '/' . $path . '/src');
* @endcode
*/
function system_register($type, $name, $uri) {
drupal_get_filename($type, $name, $uri);
drupal_classloader_register($name, dirname($uri));
@trigger_error('system_register() is deprecated in Drupal 8.8.0 and will be removed before Drupal 9.0.0. There is no replacement for this function. To achieve the same functionality use this snippet: $path = \Drupal::service("extension.list.$type")->getPath($name); ' . "\\Drupal::service('class_loader')->addPsr4('Drupal\\\\' . \$name . '\\\\', \\Drupal::root() . '/' . \$path . '/src'); See https://www.drupal.org/node/3035275.", E_USER_DEPRECATED);
\Drupal::service('class_loader')->addPsr4('Drupal\\' . $name . '\\', \Drupal::root() . '/' . dirname($uri) . '/src');
}
/**
......
<?php
namespace Drupal\Tests\Core\ClassLoader;
use Composer\Autoload\ClassLoader;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Tests\UnitTestCase;
/**
* @group ClassLoader
* @group legacy
*/
class ClassLoaderTest extends UnitTestCase {
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$container = new ContainerBuilder();
$container->set('app.root', $this->root);
$class_loader = $this->prophesize(ClassLoader::class);
$class_loader->addPsr4('Drupal\\foo\\', $this->root . '/modules/bar/src')->shouldBeCalled();
$container->set('class_loader', $class_loader->reveal());
\Drupal::setContainer($container);
}
/**
* @expectedDeprecation drupal_classloader_register() is deprecated in Drupal 8.8.0 and will be removed before Drupal 9.0.0. Use the method ::addPsr4() of the class_loader service to register the namespace. See https://www.drupal.org/node/3035275.
* @see drupal_classloader_register()
*/
public function testDrupalClassloadeRegisterDeprecation() {
include_once $this->root . '/core/includes/bootstrap.inc';
drupal_classloader_register('foo', 'modules/bar');
}
/**
* @expectedDeprecation system_register() is deprecated in Drupal 8.8.0 and will be removed before Drupal 9.0.0. There is no replacement for this function. To achieve the same functionality use this snippet: $path = \Drupal::service("extension.list.$type")->getPath($name); \Drupal::service('class_loader')->addPsr4('Drupal\\' . $name . '\\', \Drupal::root() . '/' . $path . '/src'); See https://www.drupal.org/node/3035275.
* @see system_register()
*/
public function testSystemRegisterDeprecation() {
include_once $this->root . '/core/includes/module.inc';
system_register('module', 'foo', 'modules/bar/foo.module');
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment