Project:Patterns
Version:6.x-1.x-dev
Component:Code
Category:support request
Priority:normal
Assigned:Unassigned
Status:closed (works as designed)

Issue Summary

Is it possible to use Patterns to execute some custom actions, like 'Update node 12 by replacing word "[test]" to "name"' ?
I'm looking into \patterns\components files and as far as I see all possible patterns use Drupal form API - but I'd like to use my own PHP code.
Thanks in advance.

Comments

#1

I don't think this is the intended use of patterns, but what you're describing is perfect for the update hook system in drupal. Here's the API page for more info.

http://api.drupal.org/api/function/hook_update/6

#2

I don't think that hook_update is a good idea here. I'd like to execute my pattern file once on several websites, and I need to replace some word in some node only once. I think that Patterns is a perfect fit for such tasks, and hook_update is good for frequent-running tasks and it's also hardcoded in module, isn't it?

#3

I think it's quite appropriate and almost standard use case for the manner in which hook_update is used, even if submitting it to multiple sites. It is stored in a module but you could have a module that only implemented site updates and then deploy that to your various sites. You would just run update.php and your changes would be applied. A module is simply the most appropriate place to put code; any other mechanism provides too many security holes to make it feasible, IMO.

You could write a pattern that pre-replaced the string and inserted the final output, but I believe that's the extent of what panels can do. I'm not the maintainer, so one of them might have further ideas, but I did run into that constraint as I was testing its abilities and just wanted to share my experience and a possible solution.

Having said that, if it's just this one (or a few) changes occurring a single time, both a module or a pattern might be overkill.

#4

I think it's a good use case and certainly something worth considering for inclusion with the module. Sarva and/or Vaish would be more educated to answer on the actual feasibility of implementing something like that.

We've discussed the idea of being able to include PHP in Patterns but haven't really though it through in depth in relation to any security issues.

It might be handled simply by including a separate permission for "Allow PHP in Patterns" and leaving it up to the users to turn that on if they want it. :-)

#5

Status:active» closed (works as designed)

As mentioned in comment #3, currently you can only write a pattern that would contain already replaced text and would just update the node in a regular way. In other words what you are asking is not possible. As a general rule, patterns support anything that can be achived by submitting a form witin Drupal's admin interface. If a form to acomplish some task doesn't exist (as in this case), most likely, patterns won't support it as well.

This is certainly interesting use case worth considering, but I don't think it will be implemented in the patterns module any time soon.

nobody click here