I am also trying to fetch the node which I am adding a validation rule to its form, and when I add the fetch by entity action I can't see the node id. I am unsure into how to expose something in a way other actions can pick it up, but maybe you do.

Comments

jordojuice’s picture

It 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 $form array (form), $form_state array (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.

ohthehugemanatee’s picture

Seems 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.

berenddeboer’s picture

Status: Active » Needs review
StatusFileSize
new4.04 KB

Here 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.

berenddeboer’s picture

Title: Somehow exposed the nid of the validated form (if a node) to be used in a fetch by entity action » Somehow expose the nid of the validated form (if a node) to be used in a fetch by entity action
berenddeboer’s picture

StatusFileSize
new5.85 KB

I missed passing $node at a few places. Here an improved version.

berenddeboer’s picture

StatusFileSize
new6.2 KB

One 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.

berenddeboer’s picture

StatusFileSize
new6.2 KB

One improvement upon #6, needed to check if log was actually set at all, else we get a notice.

liberatr’s picture

The 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.

kaizerking’s picture

is this working?

nimek’s picture

Patch 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).

caminadaf’s picture

Issue summary: View changes
StatusFileSize
new5.95 KB

I 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.

caminadaf’s picture

Title: Somehow expose the nid of the validated form (if a node) to be used in a fetch by entity action » Expose the entity to be used by actions and conditions, if entity form
kenorb’s picture

StatusFileSize
new5.95 KB

Re-roll against the recent dev.

rafaelpedrosanto’s picture

Status: Needs review » Reviewed & tested by the community

Patch #13 fails with errors:

Checking patch rules_forms.module...
warning: rules_forms.module has type 100755, expected 100644
error: while searching for:
    $form_info = rules_forms_get_form_info($form_id);
    $button = $form_state['triggering_element'];
    if (isset($button['#rules_forms_element_id']) && isset($form_info['submit'][$button['#rules_forms_element_id']])) {
      rules_forms_invoke_event('button_' . str_replace(':', '_', $button['#rules_forms_element_id']) . '_validate', $form, $form_state, $form_id);
    }
  }
}

error: patch failed: rules_forms.module:145
error: rules_forms.module: patch does not apply
Checking patch rules_forms.rules.inc...
warning: rules_forms.rules.inc has type 100755, expected 100644

.
Patch #11 works fine. RTBC

kenorb’s picture

@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.module before.

  • caminadaf committed 8799e82 on 7.x-1.x
    Issue #1448064 by berenddeboer, caminadaf: Expose the entity to be used...
caminadaf’s picture

Status: Reviewed & tested by the community » Closed (fixed)

@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.

caminadaf’s picture

Status: Closed (fixed) » Fixed

Status: Fixed » Closed (fixed)

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