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.

CommentFileSizeAuthor
#6 workspace.patch448 bytesMichel Poulain

Comments

smacphail’s picture

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:

    if (isset($options[$node_type])) {
      drupal_goto('node/add/' . $node_type);
    }

You'd modify it to look like:

    if (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?

frank ralf’s picture

Status: Active » Needs review

Thanks for the hack! Has anyone tested the code yet?

Frank

smacphail’s picture

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.

frank ralf’s picture

Thanks for the feedback. Will include the patch in the next commit to HEAD.

Frank

turadg’s picture

Status: Needs review » Reviewed & tested by the community

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.

Michel Poulain’s picture

Status: Reviewed & tested by the community » Patch (to be ported)
StatusFileSize
new448 bytes

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]

frank ralf’s picture

Hi Michel,

Thanks for your patch. Have you tried the Dev version? The above mentioned hack should be already incorporated there.

Cheers,
Frank

StudioARE’s picture

Good to hear this issue have been fixed.

Could you release a "non-dev" version with this issue fixed as well? Just so it would look a bit nicer for anyone else stumbling upon this module. :)

-Are