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.
It's probably low-priority relative to other stuff, but I think DMU should cover the arg() function, which has been kicked out of Drupal 8: https://www.drupal.org/node/2274705
Comments
Comment #1
phenaproximaOK, so...turns out current_path() still exists in D8. I didn't see a deprecation notice or anything. So what if we converted calls as below? It's a bit hacky, but it also seems like the path of least resistance. Thoughts?
arg(2)
to
explode('/', current_path())[2]
Comment #2
webchickI wouldn't count on current_path() sticking around long-term (it'll probably move to something like \Drupal::currentPath()) but looking at the conversions in #788900: Deprecate and remove usages of arg() I think that's a suitable workaround. The "right" way to solve it is to stop using arg() and instead check the route name, but IMO your proposal is totally fine for an automated conversion script.
Comment #3
webchickComment #4
phenaproximaThis is going to need a dedicated plugin to handle the two basic uses of arg():
1) if
(arg(2) == 'foo')
must become something like this:Testing an arg() value against another value should be changed to use the path matching service. It's functionally identical, and it's probably the closest we'll get to converting that use of arg().
2)
$foo = arg(2)
I don't remember how to get the current request path (current_path() still exists without a deprecation notice, but as webchick said I wouldn't count on it sticking around), but this needs to be replaced with something like:
If anyone wants to take this on, let this be your guide :) If not, I'll get to it eventually.
So to boil it down, from a code parsing standpoint the two possible "contexts" in which arg() appears are:
1) As one side of a comparison. (==, ===, !=, >, <, >=, <=, and hopefully I'm not forgetting any)
2) Anything else