Following the greatest idea from mcrittenden in #431976: Add wrapper function for current url (i.e., $_GET['q'])

The same but for path aliases.

Comments

nevets’s picture

Why not just have drupal_get_path_alias() handle a null path, using $_GET['q] if the path is null. Removes the need for yet another function.

mcrittenden’s picture

I think nevets' idea is a good one, just have to make sure it's documented extremely well so that knowledge of that functionality doesn't get lost in the haze.

akahn’s picture

What do people think of having drupal_get_path_alias() default to using the current path? The function signature could be something like drupal_get_path_alias($path = $_GET['q'], $path_language = ''). (Or, assuming #431976: Add wrapper function for current url (i.e., $_GET['q']) gets committed, drupal_get_path_alias($path = current_path(), $path_language = '').)

mcrittenden’s picture

akahn: so far, that's three of us in agreement. Caktux?

caktux’s picture

Definitely +1 for that, simply using actual functions more logically. I don't think it would break anything and, well it would probably just mean patching drupal_get_path_alias with your current code and test..

caktux’s picture

Status: Needs review » Needs work
akahn’s picture

Status: Needs work » Needs review
StatusFileSize
new1.23 KB

Here's a patch with the above ideas. Any feedback is appreciated.

Status: Needs review » Needs work

The last submitted patch failed testing.

mcrittenden’s picture

Akahn: Why not just set $path = $_GET['q'] in the function's param rather than setting to NULL and resetting? Am I missing something?

akahn’s picture

I think PHP does not allow using a variable as a default value for a parameter.

mcrittenden’s picture

Oh, DUH! In that case, the only problem I see is that the first comment is multi-line and has more than one sentence. From http://drupal.org/node/1354

The first line of the block should contain a brief description of what the function does, beginning with a verb in the form "Do such and such" (rather than "Does such and such"). A longer description with usage notes may follow after a blank line.

So I'd say fix the comment and reroll to match head and we're good to go.

akahn’s picture

Status: Needs work » Needs review
StatusFileSize
new1.19 KB

Thanks for the catch. The note about using the current page when there is no path argument is now in its own paragraph.

mcrittenden’s picture

Bot likes it, and it looks good to me.

chx’s picture

Status: Needs review » Reviewed & tested by the community

Thats good.

caktux’s picture

Status: Reviewed & tested by the community » Needs review

Awesome :D Thanks guys!

caktux’s picture

Status: Needs review » Reviewed & tested by the community
webchick’s picture

Status: Reviewed & tested by the community » Fixed

Nice! :) Committed to HEAD.

The only adjustment I made was I switched "An optional internal Drupal path" back to "An internal Drupal path." Both the comment above and the = NULL implies that it's optional, IMO. I did leave the langcode the same as it was (with the word "optional") because that's not the primary focus of this function, so it really is optional.

I also wrapped the "If no path is provided..." at 80 chars.

I wonder if we should maybe look at some point at harmonizing the names of current_path(), base_path(), and drupal_get_path_alias() so it's more clear they are related.

caktux’s picture

Another big thanks from me guys! :D How about we add path_alias() which would be a simple wrapper for drupal_get_path_alias()? Somehow it would group the three functions while keeping the "older" drupal_get_path_alias() intact ;)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.