Closed (fixed)
Project:
Rules Forms Support
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
21 Feb 2012 at 13:30 UTC
Updated:
23 Mar 2016 at 19:43 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
jordojuice commentedIt would have to be passed as a variable in the form event in order to be accessible in your rule. But since Rules Forms is agnostic as far as what page it's on - e.g. not all forms are on nodes - we can't tell Rules that a node object is one of the event's parameters because the simple fact is that a node object will not always be available. Rules Forms has to explicitly tell Rules what variables it is passing so it knows what variables to tell you are available - the
$formarray (form),$form_statearray (form state), and a bunch of element IDs (like 'textfield:title' or 'textarea:body:und:0:value') are what it passes.Theoretically, Rules Forms could determine whether a particular form is on a certain type of page - a node page - and load the related object to pass to Rules. It may be useful to pass a node object, but the issue is that it's impossible to determine whether a particular form will always be related to a node page. But too much abstraction in this type of feature would not be a good thing. In other words, if this type of feature were implemented where Rules Forms determined whether a form was on a node page at the time it was activated, you could activate the search form from node/1. Rules Forms would then assume that search_block_form was on a node page and it would tell Rules that it can pass a node object as a variable, but that fact is that the search form can appear on many pages other than node forms. So, when this feature is applied to other types of pages it doesn't work. However, in the case of nodes I think the node object is actually stored in the form as
$form['#node'], so it could still be done by checking for the node object. But nodes are probably the only types of pages from which Rules Forms could pass an additional argument like that. There would need to be some changed in the internal rules_forms_event_info variable - a flag identifying a particular form as a node form - but I think it can be done. Maybe I'll put together a patch and try it out.Comment #2
ohthehugemanatee commentedSeems like the approach here would be an entities based one. Offer an action to "load the entity object from the form". People can use rules components to operate on the entity object, which in this case would mean first validating it as a node.
Comment #3
berenddeboer commentedHere a patch which supplies the node parameter. Minimal testing so far, i.e. behaviour not tested in cases where a form doesn't have a node.
Comment #4
berenddeboer commentedComment #5
berenddeboer commentedI missed passing $node at a few places. Here an improved version.
Comment #6
berenddeboer commentedOne more extension: the node->log field is not set for some reason, which is annoying if you want to check if it is set under certain circumstances. I "patched" that here as well. Not sure if there is any better place or any better way, but it does the job admirably.
Comment #7
berenddeboer commentedOne improvement upon #6, needed to check if log was actually set at all, else we get a notice.
Comment #8
liberatrThe patch #7 is working for me - so glad to be able to get the node in my rule.
Edit: this seems to have the value of the node before it is saved.
Comment #9
kaizerking commentedis this working?
Comment #10
nimek commentedPatch 7 works but now i have error when i try to use form rules to alter views exposed filters form
RulesEvaluationException: Argument node is missing. w RulesPlugin->setUpState() (line 717 of /home/domain/www/sites/all/modules/rules/includes/rules.core.inc).
Comment #11
caminadaf commentedI took the liberty of taking the patch in #7 and transforming it into entity, to tha this way it is more generic and can work with more scenarios thatn simply using node.
Comment #12
caminadaf commentedComment #13
kenorb commentedRe-roll against the recent dev.
Comment #14
rafaelpedrosanto commentedPatch #13 fails with errors:
.
Patch #11 works fine. RTBC
Comment #15
kenorb commented@rafaelpedrosanto The patch #13 should work, but you couldn't apply, because your local file rules_forms.module had 755 permission which was not correct. You should do:
chmod 644 rules_forms.modulebefore.Comment #17
caminadaf commented@kenorb Your patch didn't apply on a clean clone of this module's repository. You sure that you don't have any other patches applied? Since this module's last updated date was on 2012, there was nothing new on the dev branch, so there was no need to re-roll it.
Anyways, this was commited to the branch 7.x-1.x, so I'm closing this issue.
Thank you for your inputs.
Comment #18
caminadaf commented