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.
Files: 
CommentFileSizeAuthor
#19 d7_rules_bundle_condition.patch7.9 KBfago
#10 1472752-10-rules-condition-entity_is_of_bundle.patch5.89 KBSimon Georges
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch 1472752-10-rules-condition-entity_is_of_bundle.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]
#4 1472752-4-rules-condition-entity_is_of_bundle.patch5.83 KBDavid Stosik
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch 1472752-4-rules-condition-entity_is_of_bundle.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]
#3 1472752-3-rules-condition-entity_is_of_bundle.patch4.73 KBDavid Stosik
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch 1472752-3-rules-condition-entity_is_of_bundle.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

Comments

Status:Active» Needs review
StatusFileSize
new4.73 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch 1472752-3-rules-condition-entity_is_of_bundle.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

Hello,

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

StatusFileSize
new5.83 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch 1472752-4-rules-condition-entity_is_of_bundle.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

Hello again,

I added a simpletest test that verifies that an article node passes the condition successfully.

Thanks,
David

Just adding a David Stosik++ on this issue.

I 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

Status:Needs review» Needs work

Notices in #6 need to be fixed otherwise it seems to work well.

Those notices should all be fixable with an existence check...

<?php
function rules_entity_action_bundle_options($element) {
 
$bundles = array();
  if (!empty(
$element->settings['type'])) {
   
$entity_info = entity_get_info($element->settings['type']);
    foreach (
$entity_info['bundles'] as $bundle_name => $bundle_info) {
     
$bundles[$bundle_name] = $bundle_info['label'];
    }
  }
  return
$bundles;
}
?>

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.

Sorry I can't provide an amended patch, I'm a bit rushed at the moment.

Status:Needs work» Needs review
StatusFileSize
new5.89 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch 1472752-10-rules-condition-entity_is_of_bundle.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

Patch as per #8, all credits go to David Stosik and kingandy.

Status:Needs review» Reviewed & tested by the community

thank you, guys. it works for me perfect.

Status:Reviewed & tested by the community» Needs work

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

Assigned:Unassigned» fago

I'm going to take care of this.

Hi, 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

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

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.

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

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

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

Status:Needs work» Fixed
StatusFileSize
new7.9 KB

I've completed it as discussed + pushed it (see attached patch). Thanks!

Thanks!

Hi 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?

Status:Fixed» Closed (fixed)

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

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