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

phenaproxima’s picture

OK, 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]

webchick’s picture

I 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.

webchick’s picture

Version: » 8.x-1.x-dev
Priority: Normal » Major
phenaproxima’s picture

This 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:

// @FIXME
// Stop using arg()! More info at ...
if (\Drupal::service('path.matcher')->matchPath(current_path(), '*/*/foo'))

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:

// @FIXME
// Stop using arg(). More info at ...
$foo = explode('/', \Drupal::request()->getRequestPath())[2] // ...or however we get the current path in D8

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