Problem/Motivation

Part of #2999721: [META] Deprecate the legacy include files before Drupal 9 for drupal_classloader_register().

Proposed resolution

Deprecate drupal_classloader_register() & system_register() . Use directly the class_loader service, method ::addPsr4(), where needed.

Remaining tasks

None.

User interface changes

None.

API changes

None.

Data model changes

None.

Release notes snippet

None.

Comments

claudiu.cristea created an issue. See original summary.

claudiu.cristea’s picture

Status: Needs work » Needs review
StatusFileSize
new2.39 KB

Patch.

berdir’s picture

+++ b/core/includes/module.inc
@@ -72,7 +72,7 @@ function system_list_reset() {
  */
 function system_register($type, $name, $uri) {
   drupal_get_filename($type, $name, $uri);
-  drupal_classloader_register($name, dirname($uri));
+  \Drupal::service('class_loader')->addPsr4('Drupal\\' . $name . '\\', \Drupal::root() . '/' . dirname($uri) . '/src');

system_register() seems unused in core, instead of updating the usage there we could also just not touch it and instead deprecate it too? Done that in some cases, but might be easier to update it.

claudiu.cristea’s picture

Title: Deprecate drupal_classloader_register() » Deprecate drupal_classloader_register() & system_register()
Issue summary: View changes
StatusFileSize
new3.51 KB
new5.47 KB

@Berdir,

Yeah, let's do that. However, I cannot keep that untouched as is hard to test. Added deprecation tests, updated title, IS, CR.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

mile23’s picture

Status: Needs review » Needs work
+++ b/core/includes/bootstrap.inc
@@ -790,8 +790,21 @@ function drupal_get_profile() {
+ * @deprecated in Drupal 8.7.0, will be removed before Drupal 9.0.0. Use the
...
+  @trigger_error('drupal_classloader_register() is deprecated in Drupal 8.7.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);

+++ b/core/includes/module.inc
@@ -69,10 +69,18 @@ function system_list_reset() {
+ * @deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. There is
...
+  @trigger_error('system_register() is deprecated in Drupal 8.7.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);

+++ b/core/tests/Drupal/Tests/Core/ClassLoader/ClassLoaderTest.php
@@ -0,0 +1,46 @@
+   * @expectedDeprecation drupal_classloader_register() is deprecated in Drupal 8.7.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.
...
+   * @expectedDeprecation system_register() is deprecated in Drupal 8.7.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.

Deprecated in 8.8.x now but LGTM otherwise.

naveenvalecha’s picture

Status: Needs work » Needs review
StatusFileSize
new5.47 KB
new5.15 KB

Addressed #6

andypost’s picture

Status: Needs review » Reviewed & tested by the community

Looks ready

claudiu.cristea’s picture

The CR branch should be updated too.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed 8165415 and pushed to 8.8.x. Thanks!

  • catch committed 8165415 on 8.8.x
    Issue #3035274 by claudiu.cristea, naveenvalecha, Berdir: Deprecate...
naveenvalecha’s picture

#9, Updated CR branch.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

quietone’s picture

publish the cr