Trying to implement your idea from #832046-5: Rules API Changes from 6.x to 7.x.
Inside rules, it works. For the event, the entity is there and if there were a "entity is type" condition (another issue), you could do fun stuff with it :) For granting points action, every entity is listed as a possible data selector (users, private messages, you name it..). BUT..
I'm now inside my action callback function, and I'm getting $entity passed. Trick question: How do I get the type and id of that thing? Because what I have is the raw entity object, not a wrapped object or something like that. I don't think it's possible to write a magic entity_get_type($entity) function because the object probably doesn't contain any information about that. (At least private messages don't)
What about this: Add a new option to the parameter definition and call it 'keep_wrapper' or something like that, defaulting to FALSE. If set to TRUE, the EntityMetadataWrapper class is passed to the action. It's easy to get the id and type of that...
Comments
Comment #1
BenK CreditAttribution: BenK commentedSince I'm working with Berdir on this, tracking this thread...
Comment #2
fagoYou can access the wrapper by using $state->currentArguments[$parameter_name] - as example have a look at rules_action_data_set(). An option to not unwrap the entity would make sense to me too and shouldn't be hard to do as rules_unwrap_data() already gets the parameter info passed. Maybe better use 'no_unwrap' => TRUE .
Comment #3
BerdirI can confirm that it works by using currentArguments :)
Adding a no_unwrap option would be nice, but isn't urgent then...
Comment #4
fagoComment #5
fagoI've recently added this, it's called 'wrapped' though.
Comment #6
BerdirDoes that also mean that it is consistent now? :) And what is the default value?
Reason that I'm asking is that I had to use this code a lot "is_object($params['user']->uid) ? $params['user']->getIdentifier() : $params['user']->uid".
EntityValueWrapper has a __toString() method, but that doesn't work when you cast it to an (int).
Comment #7
fago>Does that also mean that it is consistent now? :) And what is the default value?
It is FALSE, while for parameters of type 'entity' it's on by default.
I don't see though, when it is not consistent. Please clarify.
Comment #8
BerdirMaybe that was changed (that was basically my question ;)) but when I wrote the rules2 integration for privatemsg and userpoints, it depended on where the object came from.
If I remember correctly, if it's a wrapped entity then it is not unwrapped and when it was passed in as a normal entity object, then it was unwrapped.