When setting up rules, asserting that a flagging entity is of a specific bundle fails.

When adding the condition - flagging is of bundle - it fails with the following

Call to undefined method stdClass::type()

I was able to work around this by calling entity_metadata_wrapper on the flagging object before passing it to rules. However, the bundle check fails for reasons unknown.

This is necessary since rules does not allow accessing of the bundle fields until you first add the above rule.

Comments

joachim’s picture

Version: 7.x-3.3 » 7.x-3.x-dev
Component: Flag core » Rules integration
shabana.navas’s picture

Will take a look at it.

shabana.navas’s picture

Do you mean you are getting this error when you are adding the condition 'Entity is of Bundle'? Not able to duplicate this. Would appreciate an export of your rule so that I can re-create this error.

drone.ah’s picture

The rule is currently on a "flagged a field collection" so you might need that module installed for the rule to be active.

The flag is set to use javascript and the javascript call fails (I have devel enabled with krumo backtrace which I suspect is what breaks the javascript).

The rule is as follows:

{ "rules__ve_points_on_flagging" : {
"LABEL" : "-ve Points on Flagging",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [ "rules", "flag" ],
"ON" : { "flag_flagged_inaccurate" : [] },
"IF" : [
{ "entity_is_of_bundle" : {
"entity" : [ "flagging" ],
"type" : "flagging",
"bundle" : { "value" : { "inaccurate" : "inaccurate" } }
}
}
],
"DO" : [ { "drupal_message" : { "message" : "It Worked!" } } ]
}
}

From the error log:

PHP Fatal error: Call to undefined method stdClass::type() in {...}/rules/modules/entity.eval.inc on line 165,

shabana.navas’s picture

I have never used the field collection module, so, let's see how this goes...

shabana.navas’s picture

Finally got some time to test this. It is actually working just fine for me. I created a Playlist node with a field_collection field. I have set up a flag on the field_collection. I have the following rule trigger (identical to yours) when the I flag the field_collection field.

{ "rules_test_field_collection" : {
"LABEL" : "Test field_collection",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [ "rules", "flag" ],
"ON" : { "flag_flagged_like_my_tracks" : [ ] },
"IF" : [
{ "entity_is_of_bundle" : {
"entity" : [ "flagging" ],
"type" : "flagging",
"bundle" : { "value" : { "like_my_tracks" : "like_my_tracks" } }
}
}
],
"DO" : [ { "drupal_message" : { "message" : "It worked." } } ]
}
}

I get the 'It worked.' message after I flag the field. I have the devel module with krumo backtrace enabled. So this is working perfectly for me. I am not sure what could be going wrong on your end.

apmsooner’s picture

Status: Active » Closed (duplicate)
Parent issue: » #2269391: Add rules action to fetch flagging by user for a particular entity