Change record status: 
Project: 
Introduced in branch: 
9.3.x
Introduced in version: 
9.3.0
Description: 

drupal_get_path() and drupal_get_filename() have been deprecated. Use an extension type-specific \Drupal\Core\Extension\ExtensionList::getPath() and \Drupal\Core\Extension\ExtensionList::getPathname() instead where possible. You can use \Drupal::service('extension.path.resolver')->getPath()/getPathname() and dynamically pass in the extension type as the first parameter.

These methods will throw:

  • \Drupal\Core\Extension\Exception\UnknownExtensionException if the extension is not found.
  • \Drupal\Core\Extension\Exception\UnknownExtensionTypeException if the extension type is not found.

drupal_get_path()

Before After
drupal_get_path('module', 'node') \Drupal::service('extension.list.module')->getPath('node')
drupal_get_path('theme', 'seven') \Drupal::service('extension.list.theme')->getPath('seven')
drupal_get_path('profile', 'standard') \Drupal::service('extension.list.profile')->getPath('standard')

If you want to specify the type dynamically you can use:

Before After
drupal_get_path('module', 'node') \Drupal::service('extension.path.resolver')->getPath('module', 'node')

drupal_get_filename()

Before After
drupal_get_filename('module', 'node') \Drupal::service('extension.list.module')->getPathname('node')
drupal_get_filename('theme', 'seven') \Drupal::service('extension.list.theme')->getPathname('seven')
drupal_get_filename('profile', 'standard') \Drupal::service('extension.list.profile')->getPathname('standard')

If you want to specify the type dynamically you can use:

Before After
drupal_get_filename('module', 'node') \Drupal::service('extension.path.resolver')->getPathname('module', 'node')

API additions for the class \Drupal\ckeditor\CKEditorPluginBase

The class \Drupal\ckeditor\CKEditorPluginBase gets two new public methods: getModuleList() and getModulePath($module_name). The first method returns the module list service (\Drupal::service('extension.list.module')). The second method the module path for the given module name (\Drupal::service('extension.list.module')->getPath($module_name)).

Impacts: 
Module developers

Comments

adam_bear’s picture

Why not a static method::getPath for a common function?

My theme was D10 ready excepting this change, which broke one of my methods - Drupal API lives up to it's legacy and still seems unreliable... I got it working, but it seems a bit retarded to need to instantiate the object or copy the function locally...

Kind regards,
--Adam

taggartj’s picture

Now i have to make a patch for Drupal core with this some where in it.
as sure I can fix my own code but not everyones.

Again if its easy to leave it in, then leave it in.



// #Add this back in 
function drupal_get_path($type, $name) {
  /**
  drupal_get_path('module', 'node')	\Drupal::service('extension.list.module')->getPath('node')
  drupal_get_path('theme', 'seven')	\Drupal::service('extension.list.theme')->getPath('seven')
  drupal_get_path('profile', 'standard')	\Drupal::service('extension.list.profile')->getPath('standard')
   */
  switch ($type) {
    case 'module':
      return \Drupal::service('extension.list.module')->getPath($name);
      break;
    case 'theme':
      return \Drupal::service('extension.list.theme')->getPath($name);
      break;
    case 'profile':
      return \Drupal::service('extension.list.profile')->getPath($name);
      break;
      return false; 
  }
}