"Add new item" feature produces bad URLs for CCK content types
markj - December 9, 2008 - 00:26
| Project: | Workspace |
| Version: | 6.x-1.3 |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | patch (to be ported) |
Description
The 'Add new item' function in Workspace produces URLs to node create forms that contain underscores in CCK content type names. These URLs should contain hyphens. The result is that the user gets routed to the core Create content page that lists all the types they have access to.
For example, selecting a CCK content type of "Test type" (machine readable type test_type) and clicking on "Add new item" routes the user to http://mysite.com/node/add/test_type, whereas it should route the user to http://mysite.com/node/add/test-type.

#1
Also having the same problem.
I did a quick look in the code and came up with this hack, which seemed to work. (Sorry, don't know how to make patch files yet. :P)
You're looking for the function "workspace_add_form_submit" and the line that looks like:
<?phpif (isset($options[$node_type])) {
drupal_goto('node/add/' . $node_type);
}
?>
You'd modify it to look like:
<?phpif (isset($options[$node_type])) {
/* Start hack */
if (stristr($node_type,"_") > -1) {
$node_type = str_replace("_","-",$node_type);
}
/* End hack */
drupal_goto('node/add/' . $node_type);
}
?>
Seems pretty simple...I think?
#2
Thanks for the hack! Has anyone tested the code yet?
Frank
#3
I've been using this little hack on a production environment for the past few months, haven't heard of any issues or complaints from my users.
#4
Thanks for the feedback. Will include the patch in the next commit to HEAD.
Frank
#5
btw, it's not really a hack. it's exactly what node.module (in core) does:
foreach (node_get_types('types', NULL, TRUE) as $type) {$type_url_str = str_replace('_', '-', $type->type);
$items['node/add/'. $type_url_str] = array(
...
The check for underscores should not be included. If there are no underscores, the check will take exactly as long as no check. If there are underscores, it will take about twice as long as it scans the string twice.
I hope to see this in a release soon as it's a very simple fix to a problem that is very confusing to users.
#6
Sorry for the duplicate Issue report. I should have checked before. My fault. http://drupal.org/node/616462
This is my patch for a proper Workspace behavior :
if (isset($options[$node_type])) {- drupal_goto('node/add/' . $node_type);
+ drupal_goto('node/add/' . str_replace('_', '-', $node_type));
}
The actual node add url with Workspace :
example.com/node/add/node_type[WRONG]With this patch :
example.com/node/add/node-type[GOOD]#7
Hi Michel,
Thanks for your patch. Have you tried the Dev version? The above mentioned hack should be already incorporated there.
Cheers,
Frank