Sub-pathauto is here!!

This is a simplification and rewrite of the Subpath URL alias module for Drupal 7 that "just works."

Note: please ignore the attached file. It was attached here along with the initial issue description and there is no way to remove it :/

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jcarlson34’s picture

Hi sven. Thanks for working on this.

I would love to test the port and the patch but patching the CVS HEAD leads to hunk fails for me on both mac and pcs. Probably something wrong on my end.

@Maintainers... Any chance we could get a 7.x dev version started based off sven's patch? Many thanks.

jcarlson34’s picture

FileSize
4.59 KB

Ok so I've ended up building the patch by hand, checking twice to make sure I copied everything correctly (ugh).

So far it seems to be working great.

I've attached the updated 7.x module in a zipped file in case anyone else has patching issues and wants to test it.

sven.lauer’s picture

@jcarlson34: Not sure what the problem is. I just did a fresh CVS checkout and the patch applied cleanly ...

I'd really like to see a 7.x-dev version, as well ...

jcarlson34’s picture

Yeah its all good. Most likely I'm doing something wrong. But the updated code is still working great so kudos Sven.

Looking forward to other people testing it and seeing if we can move this towards a dev version as well.

Niklas Fiekas’s picture

Subscribe.

chriz001’s picture

subscribe

Dave Reid’s picture

FileSize
3.07 KB

Here's the code I've been working on for d7, lovingly called 'subpathauto'.

jcarlson34’s picture

Dave Reid. You're awesome. Installed it and it works great.

Even works in situations like navigating from Views to Revisions to Edit, which was not yet working in the previous patch (would just show node/1/edit in the browser).

Love the module name 'subpathauto'. My only recommendation would be to change the name in the info file from "Sub-pathauto" to "Sub-Pathauto". Sounds tougher with the extra capitalization but that's just me :)

jcarlson34’s picture

Status: Needs review » Reviewed & tested by the community

No problems found still. Marking this as RTBC.

I'm a little surprised this little module is not shipped with pathauto itself, either as a submodule or as an optional checkbox in the settings page. I'm sure there are some reasons for this but it'd be sweet to have it packaged with pathauto automatically.

jdleonard’s picture

Works well for me too, thanks!

jdleonard’s picture

Status: Reviewed & tested by the community » Needs work

Actually, seems like there's a problem. For "node/add" -> "create", "/create/blah" results in the page for "create". Shouldn't it return page not found (I don't have a content type "blah")?

Dave Reid’s picture

@jdleonard: What happens when you hit the /create/blah page? If you see the same thing as the /create page then it's working by design. When I load /node/add/blah on my local install (without subpathauto enabled) I get the same screen as /node/add.

jdleonard’s picture

Status: Needs work » Reviewed & tested by the community

Oh, bizarre! Right you are. Any idea how to prevent this? Not ideal for SEO.

jdleonard’s picture

I can't repro this on a clean d7 install so it must be related to another module, but when I go to "user/1/contact", the contact tab's URL is "/user/1/contact/ser/1/contact". "/ser/1/contact" gets added to the end another time when following the link. I don't see this anywhere else.

AgaPe’s picture

Great, that's what i need!

AgaPe’s picture

I dont know if its other module conflict or that i don't have mod rewrite enabled? but it just breaks my urls.
/?q=node/5/stream/1 goes to /?q=node etc, just the first argument is seen... I tried both #2 and #7.

BenK’s picture

Subscribing

tsvenson’s picture

Follow

dopedwizard’s picture

subscribing.

vdsh’s picture

For #16, I got the same problem than you, there was a problem in subpathauto_lookup_subpath, in subpathauto.module (module subpathauto)

This is what you need to change (start from line 102, until the end of the function):

// If no language is explicitly specified we default to the current URL
  // language. If we used a language different from the one conveyed by the
  // requested URL, we might end up being unable to check if there is a path
  // alias matching the URL path.
  $path_language = $path_language ? $path_language : $language_url->language;

  $args = arg(NULL, $path);
  $depth = min($max_depth, substr_count($path, '/'));



  
	/* start modification vdsh*/
	$tab_uri=explode('/', $path);
	$sub_path='';
  for ($i = 0; $i <= $depth; $i++) {
	
	

    if ($action == 'alias') { // Perform a search for each base path starting from the whole path, and removing the right-most segment each time
		
		// set the base_path and sub_path
		$base_path=implode($tab_uri,'/'); // url we want to check for alias
      	$aliased_base_path = drupal_get_path_alias($base_path, $path_language);
		
		
     if ($aliased_base_path != $base_path) {
        if (empty($sub_path)) $return=$aliased_base_path;
		else $return= $aliased_base_path . '/' . $sub_path;
		
			return $return;
     }
		//removes the right most segment
		if (!empty($sub_path)) $sub_path=$tab_uri[count($tab_uri)-1].'/'.$sub_path;
		else $sub_path=$tab_uri[count($tab_uri)-1];
		
		unset($tab_uri[count($tab_uri)-1]); // next segment
    }
    elseif ($action == 'source') { // Perform a search starting from the whole path with the right-most segment removed, and removing the right-most segment each time
		
		//removes the right most segment and set the base_path and sub_path
		if (!empty($sub_path)) $sub_path=$tab_uri[count($tab_uri)-1].'/'.$sub_path;
		else $sub_path=$tab_uri[count($tab_uri)-1];
		unset($tab_uri[count($tab_uri)-1]);
		
		
		$base_path=implode($tab_uri,'/'); // url we want to check for normal path
		
      $sourced_base_path = drupal_get_normal_path($base_path, $path_language);
      if ($sourced_base_path != $base_path) {
		 if (empty($sub_path)) $return=$sourced_base_path;
			else $return= $sourced_base_path . '/' . $sub_path;
			return $return;
  
     	}
    }
	
	
  }
/* end modification vdsh */

  return FALSE;
}

For me, this code works greatly !

The problem on the previous code was that the alias was looked starting from the left most segment, and we want it to start from the right most one.

Can you confirm that it works as well for you ?

Sorry if I haven't made a proper patch or stuff like that, but it is my first post on the website, please tell me if I should change something.

jeffwidman’s picture

subscribe

jm.federico’s picture

subscribe

jm.federico’s picture

I just want to point you all to http://drupal.org/sandbox/davereid/1078890 where there is a sandbox of #7

jcarlson34’s picture

@jm.federico thanks for the link!

veikko’s picture

subscribe

Shadlington’s picture

Subbing

rwohleb’s picture

subscribe

vdsh’s picture

FileSize
3.34 KB

I have created a topic on the sandbox with a patch for "complex" URL:

http://drupal.org/node/1151226

mrtoner’s picture

No obvious problems with #7 for me. I do want to note that I get kicked out of the overlay for node/edit, though.

MyXelf’s picture

Subscribing...

JGO’s picture

Subscribing

Romaq’s picture

Subscribe, I was about to report the fact sub-pathing DIDN'T work as a bug in pathauto, good thing I looked a little further. :)

fangel’s picture

Subscribe

KD Eric Depta’s picture

Good work Dave.
I hope u can publish this subpathauto soon.
The git clone helped me alot allready =)

yareckon’s picture

sub

RobKoberg’s picture

subscribe

brycesenz’s picture

subscribe

francois o’s picture

subscribe

klonos’s picture

Title: Port to D7 » Port Sub-path URL aliases module to drupal 7
Issue tags: +D7 porting, +port to d7, +d7 ports

...subscribing.

Less vague issue title, adding proper tags and I am about to update the issue's summary to point people to http://drupal.org/sandbox/davereid/1078890 and #1240464: Initial release of Subpathauto? (D7) / Current status / What needs testing ...a.k.a. "Are we there yet?".

klonos’s picture

PS: ...it would also be nice if this info (either a link to this issue here or over at subpathauto) was available to the project's page.

entrigan’s picture

Hi everyone, wanted to throw out that a subset functionality can be accomplished fairly easily using hook_url_(in/out)bound_alter. If you need a complete solution, this module is probably the way to go. However if you just have a few paths that need correcting (like node/%node/*) then you can use something like the following:

function rm_ui_url_outbound_alter(&$path, &$options, $original_path) {
  if(preg_match('|(node/\d+)(/.*)|', $path, $matches)){
    if(isset($matches[2])){
      $path = drupal_get_path_alias($matches[1]).$matches[2];
    }
  }
}

function rm_ui_url_inbound_alter(&$path, $original_path, $path_language) {
  if(preg_match('|(.*?/.*?)(/.*)|', $path, $matches)){
    $root = drupal_lookup_path('source', $matches[1]);
    if(substr($root, 0, 4) == 'node'){
      $path = $root.$matches[2];
    }
  }
}

Disclaimer: I just wrote this code and have not considered the performance or edge cases. I think it may only work for aliases what are of the form *part1*/*part2*

Dave Reid’s picture

Status: Reviewed & tested by the community » Fixed

Subpathauto 7.x-1.0 has been tagged and released. Available on http://drupal.org/project/subpathauto as soon as the packaging script finishes.

klonos’s picture

Thanx Dave!

klonos’s picture

Issue summary: View changes

...letting people know of the upcoming Subpathauto module and Extended path aliases as well.

klonos’s picture

Issue summary: View changes

...point to Sub-pathauto.

bmango’s picture

subscribe

Status: Fixed » Closed (fixed)

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

klonos’s picture

Status: Closed (fixed) » Closed (won't fix)

...actually, since this will never happen here it is more of a won't-fix. Issue summary is already updated to point to subpathauto, so we're good.

klonos’s picture

Issue summary: View changes

...note to ignore attached file.