Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
Let's add a generic condition that allows checking for multiple entity bundles (and thus asserts related fields).
- Let's work on top of the info provided by hook_entity_info() only, so we can support all entity types having bundles including terms and comments
- Allow choosing multiple bundles.
- The asserted properties/fields will be the intersection of the available properties. We should add a help text explaining that.
Comments
Comment #1
mitchell CreditAttribution: mitchell commentedUpdated component.
Comment #2
mitchell CreditAttribution: mitchell commentedWould this be related to #1702260: Add wrappers for Entity Types and Field Instances?
Comment #3
David Stosik CreditAttribution: David Stosik commentedHello,
May I suggest this patch? This could do what this issue asks for, and works for me, at least.
It adds an "Entity is of type and bundle" condition, which requires that you set a type first, before you can select bundles (the reason is that many bundles in different entity types can share the same name).
Thanks for your review,
David
Comment #4
David Stosik CreditAttribution: David Stosik commentedHello again,
I added a simpletest test that verifies that an article node passes the condition successfully.
Thanks,
David
Comment #5
Itangalo CreditAttribution: Itangalo commentedJust adding a David Stosik++ on this issue.
Comment #6
micnap CreditAttribution: micnap commentedI am getting errors when I click on the "Entity is of type and bundle" option:
Notice: Undefined index: type in rules_entity_action_bundle_options() (line 262 of /home/xxxx/public_html/sites/all/modules/rules/modules/entity.rules.inc)
Notice: Undefined index: bundles in rules_entity_action_bundle_options() (line 264 of /home/xxxx/public_html/sites/all/modules/rules/modules/entity.rules.inc)
Warning: Invalid argument supplied for foreach() in rules_entity_action_bundle_options() (line 264 of /home/xxxx/public_html/sites/all/modules/rules/modules/entity.rules.inc)
However, I am able to continue adding the condition and it seems to work fine.
Thanks,
Mickey
Comment #7
mstrelan CreditAttribution: mstrelan commentedNotices in #6 need to be fixed otherwise it seems to work well.
Comment #8
kingandy CreditAttribution: kingandy commentedThose notices should all be fixable with an existence check...
Assuming the empty array doesn't cause further problems, of course. Given that @micnap was able to continue with the notices, it seems like we should be good.
Comment #9
kingandy CreditAttribution: kingandy commentedSorry I can't provide an amended patch, I'm a bit rushed at the moment.
Comment #10
Simon Georges CreditAttribution: Simon Georges commentedPatch as per #8, all credits go to David Stosik and kingandy.
Comment #11
berdyshev CreditAttribution: berdyshev commentedthank you, guys. it works for me perfect.
Comment #12
fagoThanks. Patch looks good, however I think it should be just checking the bundle as the 90% use case is that. If you want to check the entity type also, we already have the condition for that.
Comment #13
fagoI'm going to take care of this.
Comment #14
David Stosik CreditAttribution: David Stosik commentedHi, thanks for your reply!
My concern is that if you only check bundle and not entity type, it seems impossible to make assertions on fields, and thus, afterwards, in actions, impossible to use fields attached to the exact entity_type:bundle we tried to match.
I know that 90% of the cases need only to match the bundle, but matching entity+bundle makes easier to use fields, without having to create a "entity has field" for each field we want to use.
Maybe providing both (bundle only AND entity + bundle) would be a better compromise?
Thanks,
David
Comment #15
kingandy CreditAttribution: kingandy commentedAgree with #14, an entity/bundle check that registers the relevant fields would greatly improve usability. Is that outside the scope of this issue, though? The goal here is simply to be able to check the bundle type, creating a conjoined entity/bundle condition seems like it would be a separate feature request.
Comment #16
fagoThat should not be problem in general. However, I figured that we might require the type check in case a general 'entity' argument is passed in. Thus, I'll add the entity-type parameter and try to hide it if we can derive it from the metadata.
Comment #17
kingandy CreditAttribution: kingandy commentedOr maybe I'm just being pedantic and we should go ahead and do it if it will improve the module...
I'm just wary of scope creep, and would like to see the bundle condition committed first.
Comment #18
fago>Agree with #14, an entity/bundle check that registers the relevant fields would greatly improve usability.
That's the way it works automatically - thanks to the metadata assertions. :-)
Comment #19
fagoI've completed it as discussed + pushed it (see attached patch). Thanks!
Comment #20
David Stosik CreditAttribution: David Stosik commentedThanks!
Comment #21
phenaproximaHi all - I just updated Rules to 7.x-2.3, which according to the release notes should include this patch (unless I'm misreading them). Once I do that, though, I start getting these warnings on the main Rules admin screen:
Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'rules_condition_entity_is_of_type_bundle_assertions' not found or invalid function name in FacesExtendable->__call() (line 123 of sites/all/modules/rules/includes/faces.inc).
Looking in entity.rules.inc, the function it's looking for doesn't seem to exist, although it is supplied by the patch. Do I need to apply the patch? If so, does it apply against 7.x-2.3 or the dev version?
Comment #23
micnap CreditAttribution: micnap commentedLooks like the patch is included except the entity_is_of_type_bundle condition was changed to entity_is_of_bundle, so the rules need to be updated to use the different condition.
Comment #24
basitparacha CreditAttribution: basitparacha commentedHi all,
I want to get help from you guys regarding my issues related to RULES integration with CUSTOM ENTITY types. I have a Custom Entity type with 4 bundles in custom entity, and i want to use features of Rules Module with my custom entity type like "create new entity" with "After saving a new apricot", or "Delete Entity" when given expiry date crossed to site-date and time.
There are few issues related to query:
1) When i go to 'Add Action' and i chose my custom entity name from a list, it does not show me Bundle Types of my Custom Entity.
2) There is also not showing the my entity type fields like TITLE or other fields of my costom entity type.
It is workable from Rules-Modules? if Yes then what will be critaria, and if it is does not workable from Rules Modiles only, then how it will be achieved from custom code/without adding custom code of my entity type.
Looking for your help
thanks and regards,
A.Basit