Change the code to avoid using functions, methods, constants, and services that have been deprecated in Drupal 9 and removed from Drupal 10

Created on 13 June 2023, over 1 year ago
Updated 8 November 2023, about 1 year ago

The module uses some functions and constants which have been deprecated in Drupal 8/9 and removed in Drupal 10.

  • drupal_get_path() has been deprecated in Drupal 9.3 and removed from Drupal 10. \Drupal\Core\Extension\ExtensionPathResolver::getPath() must be instead used.
  • drupal_get_filename() has been deprecated in Drupal 9.3 and removed from Drupal 10. \Drupal\Core\Extension\ExtensionPathResolver::getPathname() must be instead used.
  • file_create_url() has been deprecated in Drupal 9.3 and removed from Drupal 10. \Drupal\Core\File\FileUrlGeneratorInterface::generateAbsoluteString() must be instead used.
  • file_load() has been deprecated in Drupal 8 and removed from Drupal 9. \Drupal\file\Entity\File::load() must be instead used.
  • FILE_STATUS_PERMANENT has been deprecated in Drupal 9.3 and removed from Drupal 10. \Drupal\file\FileInterface::setPermanent() must be instead used.
๐Ÿ“Œ Task
Status

Needs review

Version

1.0

Component

Code

Created by

๐Ÿ‡ฎ๐Ÿ‡ณIndia arti_parmar

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @arti_parmar
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Prachi6824

    Hello,
    If you are getting this error Call to undefined function file_create_url() in city_zymphonies_theme_get_slider_content() it can be resolved using \Drupal::service('file_url_generator')->generateAbsoluteString($uri)

  • Issue was unassigned.
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Shreya_98

    Shreya_th โ†’ made their first commit to this issueโ€™s fork.

  • @shreya_th opened merge request.
  • Status changed to Needs review about 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Shreya_98

    Hello @zymphonies-dev
    Hope you are doing well,
    Added the MR to Call to undefined function file_create_url().
    Kindly review the changes.

    Thank you.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia sundaravigneshP

    I have face some issues like this drupal_get_path().

    Error: Call to undefined function drupal_get_path() in city_zymphonies_theme_get_slider_content() (line 126 of themes/contrib/city_zymphonies_theme/city_zymphonies_theme.theme).

    After install city_zymphonies_theme & i have solution to fix this issue.
    Please open the city_zymphonies_theme.theme file in the path of ( themes/contrib/city_zymphonies_theme/city_zymphonies_theme.theme )
    In the line 126 they have mention the drupal_get_path function theme of city_zymphonies_theme. so please add the drupal_get_path() after end of this city_zymphonies_theme_get_slider_content function.

    Here is this drupal_get_path() :

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

    After add this drupal_get_path() function, drush cr & check.

  • Status changed to Needs work about 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น
  • @rushikesh-raval opened merge request.
  • Status changed to Needs review about 1 year ago
  • Status changed to Needs work about 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น

    Since the code is calling two functions that are not defined in the latest Drupal core releases, let's change both those function calls, as providing two different patches/MRs to separately fix the two issues is not possible.

  • Status changed to Needs review about 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia rushiraval

    I have fixed this issue in MR!6 . also fixed for FILE_STATUS_PERMANENT constant which is also removed.

    I have change minimum required Drupal version to 9.3 and 10 because developed has mention it in description of theme.

  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น

    FILE_STATUS_PERMANENT has been deprecated in Drupal 9.3.x too โ†’ . The minimum required Drupal core version is correct.

Production build 0.71.5 2024