Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
many deprecated functions can be replaced by an equivalent call to the \Drupal class. rather than doing this manually and rerolling every time a patch breaks we should automate this and run the script at a time when the patch is likely to get committed. if we can make one big patch replacing lots of different functions then that will also prevent other issues needing multiple rerolls.
Comments
Comment #1
ianthomas_ukComment #2
grom358 CreditAttribution: grom358 commentedI have created a project to automate the replacement of deprecated functions, see the function_replace tool at https://github.com/grom358/d8codetools :)
Comment #3
ianthomas_ukI've linked the language_* functions to this, although they may not be particularly suited as they are services that should really be injected (we still need to open an issue for language_default() too, or possibly shuffle all those issues around so they do all language_* functions and injection at the same time).
I think the other issues linked here are straight replacements. Some are so small that the script isn't really helpful, others have 100+ replacements needed.
We've got a good chance of getting at least some of these in over the next couple of days if we can get the patches rolled and reviewed. If you roll a patch with the function_replace tool please include the command line you used, so we can use that for the reroll.
Comment #4
grom358 CreditAttribution: grom358 commentedhttps://drupal.org/comment/8592407#comment-8592407
https://drupal.org/comment/8592413#comment-8592413
https://drupal.org/comment/8592475#comment-8592475
https://drupal.org/comment/8592579#comment-8592579
Comment #5
ianthomas_ukYou can use the syntax
[#issue-comment]
to link to other issues, e.g.#2089433-43: Remove uses of deprecated XSS filter functions
.#2089433-43: Remove uses of deprecated XSS filter functions
#2093173-62: Remove all calls to drupal_json_decode(), use \Drupal\Component\Utility\Json::decode()
#2221695-3: Remove uses of deprecated URL functions
#2221755-1: Remove uses of deprecated Element functions
Comment #6
Sutharsan CreditAttribution: Sutharsan commented@grom358, great script!. I would like to use the script in #2223435: Do not use t() in block plugins anymore. Initially I made a bash script, but now I run into static functions where the replacement should not take place and your script handles this nicely
t()
calls should be replaced by$this->t()
calls in a subset of files. Would it be feasible to modify the script to make the class and alias optional? I need to call the script for a subset of classes, located in .../Plugin/... directories.Comment #7
grom358 CreditAttribution: grom358 commented@Sutharsan yes that is doable. Its built on Pharborist. The API is still a work in progress, but you can tell if the parent method is static by using $node->getParent() until you get to ClassMethodNode (if the call is inside a class method, otherwise the parent could be a FunctionDeclarationNode or even StatementBlockNode if its a top level statement). Then $method->modifiers->static !== NULL will tell you its a static method.
Comment #8
ianthomas_ukThis script is available at https://github.com/grom358/d8codetools