It would be nice to have pathauto support

CommentFileSizeAuthor
#7 path.txt3.05 KBagentrickard

Comments

agentrickard’s picture

Category: support » feature
Priority: Normal » Minor
Status: Active » Closed (works as designed)

I took a look at this and implementation is not trivial. It would also force someone (likely me) to keep track of pathauto development.

Since pathauto is not core, I'm not overly eager to support it right now.

You can also configure the module so that users who go to http://example.com/mysite are automatically redirected to the proper page http://example.com/mysite/UID/view, so adding path aliasing doesn't gain you a whole lot on the marketing or ease-of-use levels.

Let's get the real use cases and bugfixes out of the way first.

agentrickard’s picture

I was thinking more about this, and respecting path rewrites works, but keeping up with pathauto changes seems a burden.

It would be easier to create a setting for MySite that allowed admins to choose to alias mysite paths.

The option would only be active if the path.module were active.

The settings would be:

[ ] Create path aliases for user MySite pages.
[ ] Do not create path aliases.

The default path would be mysite/USERNAME == mysite/UID/view.

Would this setting need to be configurable beyond that?

If this setting were in effect, the module would create a path alias whenever someone created a new MySite (or updated an existing one).

agentrickard’s picture

Version: 4.7.x-1.x-dev » 4.7.x-3.0
Component: Code » - Type plugin
Status: Closed (works as designed) » Closed (fixed)

This is technically supported by the 4.7.x.3.0 release.

One could write a path.inc file to handle the creation of aliases. Doing so is easier to support than pathauto integration.

xamox’s picture

Yeah, all the above sounds good. Keep up the good work!

csc4’s picture

Status: Closed (fixed) » Postponed (maintainer needs more info)

I successfully did an inc for biblio but I just can't my head around how to do a path.inc for this functionality and I don't understand your remark about being technically supported by 4.7.x.3.0 as I can't seem to find any such setting?

Could you give me a pointer? or a path.inc?!

agentrickard’s picture

Status: Postponed (maintainer needs more info) » Active

It would probably be done entirely in the admin/settings/mysite tab. Most of the public hooks for MySite wouldn't be used.

We'd set up the following functions:

* mysite_type_path()
* mysite_type_path_settings()
* mysite_type_path_settings_form()
* mysite_type_path_update()

In the README, see:


/***
  2.4.6     mysite_type_{name}_update

This callback function is a hook that allows type plugins to act on a user-submitted change to a MySite page.  There are currently no implementation of this hook.
The function takes as its argument the user id $uid of the MySite page being changed.

Possible uses for this function include the creation of a path.inc that will function like the pathauto.module.

What we'd do is use the settings function to create the path rules, much like pathauto does.

Then when mysite_type_path_update() is invoked, we'd check to see if a path alias exists for the user. if not, we'd create one.

This sounds fairly simple. I'll take a quick pass at it. The only issue may be that other mysite_type_{name} functions are required for the module to function correctly.

agentrickard’s picture

Version: 4.7.x-3.0 » 5.x-1.x-dev
StatusFileSize
new3.05 KB

BTW, it took me from the time of last post until now to write the plugin.

It needs some work, but try the attached file. Put it in your mysite/plugins/types director and rename it to path.inc (Drupal.org won't let me attach a .inc file for security reasons).

path.inc, compatible and tested against MySite 5.x.1.9. You may have to make a few modifications to make it work in 4.7.x.

Some notes:

* I created two path settings: /mysite/name and /mysite/name/view, just to test. See the switch() case in mysite_type_path_update() to see how these are implemented.
* You must enable the PATH type under 'Display Settings'
* I have not tested what happens to user names with spaces or special characters. These might be a problem, though I think they are handled by http://api.drupal.org/api/5/function/path_set_alias.
* The aias is only created if you update a MySite page (add content, change settings, remoce content).

Next steps:

* Test odd user names (spaces, $#!@ characters).
* Define path mapping defaults. I don't really see a need for pathauto-style configuration. Is any data other than username really important here?
* Add an administrative setting to create aliases for all existing MySite users -- if this is needed. It might be best not to overload the {url_alias} table with users who never user their MySite page. So this feature is probably not needed, IMO.

Let me know how it works out.

agentrickard’s picture

Title: Need pathauto support. So you can have http://website.com/mysite/user_name_here. » Path alias support for mysite/name

Changing title

askike’s picture

I think this is a useful feature and am testing out the .inc file. So far, it's working for me in re-directing from mysite/user to mysite/uid. It would be helpful, though, if the location bar still showed the mysite/user address instead of the mysite/uid so users could copy the link and send it to a friend, etc. Or alternatively, maybe the link could be presented somehow to the user so it is easy to remember or forward the link. Hopefully I'm explaining this clearly enough...

Thanks for your work on this!

agentrickard’s picture

Actually I don't understand.

Drupal's behavior with path aliases is as follows:

* A given system path (/mysite/1/view) is mapped to a path alias (mysite/ken)
* All menu items and l() functions that refer to a given system path are presented to the user with the alias instead.

So when I test the path.inc, I get this when clicking on the default menu link (My drupal):

http://127.0.0.1/drupal-5.1/?q=mysite/ken

Which is equivalent to http://127.0.0.1/drupal-5.1/?q=mysite/1/view

The alias shows up in the browser URL and can be sent to others.

Because of how I have the menus implemented, the 'View MySite' tab still shows /mysite/1, so that may be what you are referring to.

askike’s picture

You're right. I overlooked the "path" tab and so missed enabling the "Automatically create path aliases" setting, but everything works perfectly now. Thanks!

agentrickard’s picture

Assigned: Unassigned » agentrickard
Status: Active » Needs review

Right, I get it.

Because of the plugin architecture of MySite, I could add the Path tab without changing the core module. Type include files can have their own settings, so that's why we can test path.inc without have to alter the core module.

After a little more acceptance testing and feedback, I'll roll path.inc into the main release.

Setting to 'patch (code needs review)'.

To test this patch, download http://drupal.org/files/issues/path.txt, rename the file to path.inc and place it in your mysite/plugins/types/ directory.

You will then see a Path tab under the MySite settings page.

Activating the Path plugin will auto-alias all MySites the next time a user updates the page (by adding content, removing content, or changing any settings).

Features for path.inc are still in flux, so commenting is open.

agentrickard’s picture

Status: Needs review » Fixed

Comments before I commit the code that I have?

askike’s picture

Works fine on my test site.

agentrickard’s picture

Version: 5.x-1.x-dev » 5.x-1.10
Status: Fixed » Closed (fixed)

I took the settings out, since there is no use-case for a path other than mysite/username.

Available in 5.x.1.10