You are here

function drupal_classloader_register in Drupal 8

Registers an additional namespace.

Parameters

string $name: The namespace component to register; e.g., 'node'.

string $path: The relative path to the Drupal component in the filesystem.

Deprecated

in drupal:8.8.0 and is removed from drupal:9.0.0. Use the class loader as injected service instance to register the namespace:

$this->classLoader
  ->addPsr4('Drupal\\' . $name . '\\', \Drupal::root() . '/' . $path . '/src');

or the following code if the service cannot be injected:

\Drupal::service('class_loader')
  ->addPsr4('Drupal\\' . $name . '\\', \Drupal::root() . '/' . $path . '/src');

See also

https://www.drupal.org/node/3035275

1 call to drupal_classloader_register()
ClassLoaderTest::testDrupalClassloadeRegisterDeprecation in core/tests/Drupal/Tests/Core/ClassLoader/ClassLoaderTest.php
@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.

File

core/includes/bootstrap.inc, line 845
Functions that need to be loaded on every Drupal request.

Code

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');
}