2

When a user submits a new node, I want the Rules module to look for other nodes with the same email field, then delete the older node and keep the new node.

When a user adds a new node, there is an email field that always stays the same which can be used as field to find nodes.

Is there any way to do this?

3
  • you need to loop on nodes, what other modules you have enebeled? as relations, vbo, views rules, ...?
    – pinueve
    Commented Jul 12, 2017 at 20:17
  • I have views rules enabled. Commented Jul 12, 2017 at 20:22
  • If it were me, I would create a new Rules Action which was passed the key and did the search-and-delete-if-found. Configuring Rules to use it would then be simple!
    – rivimey
    Commented Jul 12, 2017 at 21:08

2 Answers 2

1

with views rules is possible, a bit complicated, make a user view, you will need a contextual filter, "When the filter value is NOT available", "Provide default value", php code, then add something like:

global $user; // gets current logged in user object

 if (isset($user->field_user_address[LANGUAGE_NONE][0]['country'])) {      
  $user_country = $user->field_user_address[LANGUAGE_NONE][0]
['country'];
return $user_country;}

instead of using & returning $user_country, use & return your email field, and that view will return only the loggedin user field-email, add a relationship on node author, then add "node title" or whatever form the relationship, then apply a rule on that view and delete (or unplubish) that content. hope it helps.

EDIT: may be is over-coded my solution, just add a user view, contextual filter, loggedin user from URL, apply filters and relationships as needed to only get the node you are looking for, then apply a rule on that view.

1
  • My issue is that I am using nodes, not users to do this. Once I figure this out, I also have some custom entities via ECK that I need to do it as well on. Commented Jul 12, 2017 at 21:29
1

A possible answer to your question is to use the Views Rules module, as further detailed below.

1. About the Views Rules module

The Views Rules module makes Views data available in Rules, enabling intuitive rule configuration for dynamic data. Some details from its project page:

... provides two types of elements in Rules, configured with a "Rules" view display:

  • Views loop: A views loop is similar to a regular Rules loop, but allows looping over rows of view results.

    enter image description here

  • Collect view result rows (action): This action collects each variable in all view result rows into list variables for use in Rules.

Tip: When selecting the data type for variables in the view, if the field is an entity identifier (e.g. Node ID), you can set the data type to the entity type (i.e. Node) to directly use the variable in Rules as an entity!

2. Create a view of display type 'Rules'

After you enable the Views Rules module, you can use Views to create a view of those "other nodes with the same email field" (as in your question). Add of view of display type Rules (important, that's the key to make it work!). Here is how you can add such display:

enter image description here

Next configure the row variables, by using the link that says "edit field info", as shown here:

enter image description here

3. Create a rule using the view of display type 'Rules'

Create an appropriate Rule, using these guidelines:

  • Rules Event: after creating a new node (possibly limited to selected content types only).

  • Rules Conditions: add whatever may fit for your case (eg: limit to node authors of selected user roles only).

  • Rules Actions:

    • Use the link that says Add view loop to add a Views loop, and select the "Rules" display created in the previous step.
    • Configure the parameters and variable names.
    • For each node contained in your Views loop, perform whatever Rules Action that fits your requirement, using the variables you configured at the end of the previous step (you may have to revisit the previous step to add more similar variables there if needed). You probably want some rules Action like "delete the node".

Easy, no?

2
  • It makes sense up until the action. There is no action to compare the email address and then delete. Commented Jul 13, 2017 at 15:49
  • @NigelWaters How about adding the Conditional Rules module to allow you to add such "comparison" as part of the rules actions? Or as a variation, transform that part to a Rules Component in which you can add such "condition" (and if satisfied then, and only then) perform a delete of such node. Commented Jul 13, 2017 at 15:56

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.