2

I need to run some custom code when I go from state A to state B (using the workflow module).

Should I implement this with the Rules module and call my function from there or implement all of it in hook_workflow from a custom module?

In short, what is the Drupal approach?

3 Answers 3

1

Using the Rules module for this is indeed an option, whereas you should be able to implement your "custom code" using the Rules Action to "Execute custom PHP Code". If you do, make sure to not forget the PHP filter (otherwise you'll run into "Rules "Execute custom PHP Code" option not available ...").

Of course, that required 'PHP filter' might be your show-stopper. BUT: are you sure you need "custom code" at all? There may be alternative (site building only) techniques to even not need that "custom code" (and hence you'd avoid the need for that PHP filter also). And/or as a variation, you could write your own (custom) Rules Actions also ...

Not to forget these benefits also:

  • Less custom code (= easier to maintain and/or upgrade to future Drupal versions).
  • Possible out-of-the-box integrations with other modules, such as Flag, VBO etc.
0

If I understand your question correctly, both are Drupal approaches. Here are the main differences:

  1. If you do this through Rules, you will allow site builders / administrators to change, enable and disable this without touching the code. Also, adding new actions later on will be much easier, because you can just use the admin panel.

  2. If you do this through code, you will be able to track the changes through CVS, you will probably have no limitations on what you want to achieve, and there will be less chances that whoever manages the site does something wrong.

Ultimately, it's up to you and your client. If you don't see this changing in the future, or if it's something complex, do it in the code. Otherwise, Rules might be an easier option.

0

Thank you both for you answers. I now see that there are pros and cons between the both approaches.

I used the workflow approach with the motivation that the triggers and conditions I set up will be easier to migrate to other Drupal versions (I also tried to implement it with a custom module but the result was all but satisfying)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.