Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Splitting this off from #1031530: Add a User action "Send account e-mail", as it's really a distinct feature request from the user mail action that patch also contains.
Problem/Motivation
It would be useful to be able to test entities for properties.
Proposed resolution
Modelled on existing action "Fetch entity by property", add a condition "Entity exists by property".
Comment | File | Size | Author |
---|---|---|---|
#15 | Screen Shot 2013-06-03 at 13.20.50.png | 53.13 KB | lathan |
#15 | Screen Shot 2013-06-03 at 13.21.15.png | 76.51 KB | lathan |
#14 | Screen Shot 2013-06-03 at 13.19.05.png | 61.67 KB | lathan |
#11 | rules-entity-exists-1777204-11.patch | 2.42 KB | lathan |
#8 | rules-entity-exists-1777204-8.patch | 3.09 KB | lathan |
Comments
Comment #1
nedjoAttached patch is updated a bit from the version in #1031530: Add a User action "Send account e-mail" (removed an unneeded 'callbacks' array, updated the type of the 'value' parameter, moved code to entity files that presumably were added subsequent to the previous patch).
Comment #2
nedjoComment #3
rszrama CreditAttribution: rszrama commentedLooking at the language I used in descriptions again, it seems like the wording might falsely lead the user to believe this condition will actually load the entities it finds. I wonder if we should change it from fetched to something else, but I'm not sure what I'd change it to. : P
Comment #4
nedjoGood point. Maybe this?
[type] Specifies the type of the entity to be tested for.
[property] The property by which the entity is to be selected.
[value] The property value of the entity to be tested for.
Comment #5
nedjoUpdated patch with some simpler and, I hope, clearer descriptions.
Comment #6
kilik821 CreditAttribution: kilik821 commentedHow does the property field formatting work?
I have a field named MB_ID with machine name field_mb_id and I've tried all of the following and I still get a fatal error: "mb-id", "mb_id", "field-mb-id"
The fatal error is:
Fatal error: Unsupported operand types in /DRUPALROOT/sites/all/modules/entity/includes/entity.property.inc on line 113
It would be really nice if the property field had a drop down like when using the "fetch entity by property" action.
Comment #7
skyredwangThe PROPERTY option is indeed confusing. First all, the "PLACEMENT PATTERNS" below actually can't work at all; we should remove "PLACEMENT PATTERNS". Second, user has to input a case sensitive property name; e.g. "mail"
Comment #8
lathanHere is a reworked patch that looks up the properties and provides a drop down for the user to select from.
Comment #9
lathanComment #10
lathanpatch is broken..
Comment #11
lathanHere is one that works, sorry should have tested it first.
Comment #13
okday CreditAttribution: okday commentedhi,
I've tried the last patch and i can't set conditions. I only have the negate box and the save button.
thank you.
Comment #14
lathanCan you please give some more feedback @okday.
Attached is what you should be seeing.
Comment #15
lathanAnd here are some screen shots when creating the condition (you first need to select the entity). Maybe you missed that?
Comment #16
skyredwang#11: rules-entity-exists-1777204-11.patch queued for re-testing.
Comment #18
skyredwangalthough the test failed, but the patch works for me
Comment #19
samhassell CreditAttribution: samhassell commentedapplying the patch to the latest non-dev release requires clearing the cache before it displays correctly. Otherwise you just get the negate box, as described in #13.
Comment #20
Honza Pobořil CreditAttribution: Honza Pobořil commentedIt will be very useful when it will be possible to check multiple fileds. For example I want to validate if there is another node with same values at two separated fields.
Comment #21
Paul B CreditAttribution: Paul B commentedDoes this work with integer properties?
The reason I'm asking this is, I have an entity in mongodb (with the mongo_entity module) that has a property that is declared as integer in its hook_entity_property_info() implementation. I also have an integer field (stored in MySQL) attached to the user. Using the 'Entity exists by property' condition from the Commerce module, I'm trying to set up a rule that checks if a mongo entity exists that has a property matching the userfield. I can set up this rule (Rules recognizes that the property and the userfield are both integers) but the action doesn't trigger. If I edit the property in mongodb and make it a string, it triggers.
If I change the hook_entity_property_info() implementation and make it a string, Rules of course notices that the types don't match.
Comment #22
mjcarter CreditAttribution: mjcarter commentedSweet, works well, though I'm not getting an option to switch to direct input with token replacement, whereas there is one in the Commerce_checkout version does.
I got it to work how I needed by changing the code in the patch so that the type of the last 'value' field is 'text' rather than 'unknown'
Comment #23
nykooa CreditAttribution: nykooa commentedpatch #8 doesn't work for me (rules 7.x-2.6).
patch #11 works so fine! Thank's :-) But I'm worried about the failed test... Is there a way to correct it?
Comment #24
jetwodru CreditAttribution: jetwodru commentedHi,
#8 or #11 ? Rules should have this feature included coz we always want to check if the entity already exists before creation.
Often, I'm worried with patches as all these will become broken after upgrading to the newer version of the module. Recently just patched the Drupal Core, Entity API and now Rules, I wish all these patches will be included in the newer version without breaking the existing sites. Very often, I'd also forgotten which modules I'd patched and only I realized when it's broken after upgrade :p Thanks
Comment #25
Bojhan CreditAttribution: Bojhan commentedI am not sure how to resolve the failing tests, how do you specify a type when it is actually unknown?
The patch itself works fine :)
Comment #26
eileenmcnaughton CreditAttribution: eileenmcnaughton commentedJust looking at the patch - it returns true or false depending on the existence of the fetchable entity - would be more useful if it provided the list that exists back too - as the list could then be used for the next condition
Comment #27
tobiasbIn patch #11 there no callback for the option list.
Comment #28
LeeUDO CreditAttribution: LeeUDO commentedIs there any way to extend this by allow the checking of multiple fields?
example
Is there a ball which is "blue" and "10ft wide"??
Comment #29
TanvirAhmad CreditAttribution: TanvirAhmad commentedThough #11 failed the test, but it is working for me.
Cheers
Comment #30
mjcarter CreditAttribution: mjcarter commentedAny feedback on whether the value being currently 'unknown' should be 'text' as in how this is set up in commerce_checkout?
In commerce_checkout is:
This then allows direct input with token replacement.
Comment #31
nykooa CreditAttribution: nykooa commented#11 works fine for me... until I update entity to 7.x-1.4
Comment #32
kitikonti CreditAttribution: kitikonti commentedIs it possible that this condition has a conflict with an access module? I have a custom access module and if i enable it, it seems the condition dont work. If i disable it the rule works like expected. My custom access module creates records for the same content type i use in the condition. Is it possible that the condition dont have access?
Comment #33
nykooa CreditAttribution: nykooa commentedSorry, my mistake. #11 works with the Entity update. But, it's the update of entityform to 7.x-2.0-beta3 version that is the source of my problem.
No conflict with any acces module. It's a simple rule that create a new user (if user exist) with values from an entityform submittion.
Comment #34
kitikonti CreditAttribution: kitikonti commentedSo for everyone who comes to the same problem. There is a problem with access modules if the user who triggers the rule has no access to the entity i use in the condition. The same problem is with the "Fetch entity by property" which was the model for this module. The problem is because this action and condition use a function which checks the access. This must not be a Problem for everyone.
So but in my case it was a problem, so i created a module with my own condition which uses EntityFieldQuery(), because there i could set a user to run the query. My condition searches for a email address in a profile content type. Here is a code example:
Comment #35
ShaunDychko CreditAttribution: ShaunDychko commentedAnother solution is to use the condition which checks the number of results from a VBO view. You can pass Rules tokens as arguments to the View.
Comment #36
Bojhan CreditAttribution: Bojhan commentedI am wondering if this is something the Rules maintainers could take a look at. I have been patching rules, every update.
The approach in #11 seems to still work, although its failing tests.
Comment #39
khiminrm CreditAttribution: khiminrm commented#11 works for me
Comment #40
ayalon CreditAttribution: ayalon commentedI also patch rules for every update and the patch is working for me..
Comment #41
ynosh CreditAttribution: ynosh commentedHi!
There are any solution for 7.x-2.8 versión?
Thanks
Comment #42
sonicthoughts CreditAttribution: sonicthoughts commentedHi - also need way in 2.8 to see if a different entity exists. Trying to do what seems simple: create a new entity if one does not exists (by property value)
Comment #45
lamp5Better solution to change type to 'text' instead 'unknow'
Comment #46
upunkt CreditAttribution: upunkt commentedThis condition seems to have been implemented in Drupal Commerce -> commerce.rules.inc. If you use DC this patch does just nothing.
Just for reference: I was looking for a solution for "Unable to evaluate condition data_is." problems that occur when in commerce no commerce-order-unchanged entity exists.
Comment #47
TR CreditAttribution: TR commentedIf someone can provide a patch which ports that condition to Rules, then we can get this feature added to Rules.