provide a workflow-ng action

fago - December 5, 2007 - 17:40
Project:Path Redirect
Version:5.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:closed
Description

A token enabled workflow-ng action to add path redirects would be awesome. There is already an action for drupal_goto, so probably it wouldn't be hard to build one for path redirects :)

So once could let automatically generate path redirects.

#1

HorsePunchKid - December 5, 2007 - 22:47

I'm not very familiar with any of the workflow projects, but maybe this is a good excuse to learn. So basically, what we need to do is:

  • Implement path_redirect_action_info describing path_redirect_action_create or something along those lines.
  • Implement path_redirect_action_create, which would basically just call path_redirect_save with appropriate $form_values.
  • Perhaps provide a configuration form for the action so you can choose a status code.

Does that sound about right? Does this all just get included in path_redirect.module, or does it make sense to put it in path_redirect_workflow.inc and only include that if the workflow module is enabled?

#2

fago - December 10, 2007 - 14:42

yep, that sounds right :) The .inc file makes perfectly sense.
You might want to have a look at the drupal_goto action of worklfow-ng: http://cvs.drupal.org/viewvc.py/drupal/contributions/modules/workflow_ng...

You could start with that code. This action adds token integration so yours would also benefit from it!

#3

HorsePunchKid - December 24, 2007 - 20:27

I've started on this, but I'm having a little trouble seeing how the pieces fit together. I'd like to explain a hypothetical use case and see if this is the sort of thing I should expect to be able to do with Path Redirect + Workflow NG. Having a realistic test case will help me get this working correctly.

Say I'm moving a site from a bunch of static HTML pages into Drupal. I don't mind the busy work, so I'm going to recreate all these pages by hand. So what I used to have at:

http://example.com/projects/foo.html

...is now going to be at:

http://example.com/projects/foo

But I'd really like to have a URL redirect get created automatically for each of these pages since I don't have access to do this via mod_rewrite. Should I be able to set up a workflow that says:

When a node of type 'page' gets created with path 'foo/bar', create a new URL redirect from 'foo/bar.html' to 'foo/bar'.

So the net effect is that I can just go to node/add/page, create my page, and automagically get a path assigned via pathauto and a redirect created via the workflow. That would be nifty. Is that what workflow_ng should let me do?

#4

HorsePunchKid - December 24, 2007 - 23:45
Status:active» needs work

Here's a very incomplete first stab at it. It does basically work as I'd expect, but I wasn't able to get the above scenario working. I'd end up with node/add/page.html instead of foo/bar.html. PEBKAC, probably.

AttachmentSize
path_redirect-5.x-1.x_workflow_4.patch 2.51 KB

#5

HorsePunchKid - December 24, 2007 - 23:50

Here's the configuration I was trying, for what it's worth.

<?php
array (
 
'cfg_1' =>
  array (
   
'#type' => 'configuration',
   
'#altered' => false,
   
'#event' => 'node_insert',
   
'#label' => 'Redirect page from .html',
   
'#active' => 0,
   
'#module' => 'workflow-ng',
   
0 =>
    array (
     
'#type' => 'action',
     
'#name' => 'path_redirect_action_create',
     
'#label' => 'Create URL redirect',
     
'#settings' =>
      array (
       
'from' => '[node:url].html',
       
'from_args' =>
        array (
         
0 => 'node',
        ),
       
'to' => '[node:url]',
       
'to_args' =>
        array (
         
0 => 'node',
        ),
      ),
    ),
   
1 =>
    array (
     
'#type' => 'condition',
     
'#name' => 'workflow_ng_condition_content_is_type',
     
'#argument map' =>
      array (
       
'node' => 'node',
      ),
     
'#settings' =>
      array (
       
'type' =>
        array (
         
'page' => 'page',
        ),
      ),
    ),
   
'#name' => 'cfg_1',
  ),
)
?>

#6

fago - December 25, 2007 - 14:05

the patch looks good.

@test case: I don't know the token [node:url], what is it about? Probably, it gives you back the wrong value.

-> You could need a token for the path alias of a node, I don't know if this is available somewhere. Instead you could try to rebuild the path with token replacements, however in a real world scenario this might create troubles due to the path cleaning of pathauto/workflow-ng. Anyway, I think a path alias token would make sense and allow both way to work cleanly.

You could also test the correct behavior just with a fixed path redirect string and creating only one node. If that works, it works with token replacements too :)

#7

HorsePunchKid - December 29, 2007 - 21:23
Status:needs work» needs review

This version is working pretty well for me. I think you're right, fago; to do what I wanted, I would need a [node:alias] token which gave me the alias that was being assigned to the node that I'm creating. I may go ahead and commit this...

AttachmentSize
path_redirect-5.x-1.x_workflow_6.patch 3.58 KB

#8

fago - January 18, 2008 - 19:20
Status:needs review» reviewed & tested by the community

What's keeping you from committing this good patch? :)

#9

HorsePunchKid - January 19, 2008 - 19:54
Status:reviewed & tested by the community» fixed

Just letting it ripen. :)

I'm marking this fixed. If any bugs are found, new actions or conditions needed, or anything like that, please open a new issue!

#10

Anonymous (not verified) - February 2, 2008 - 20:13
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.