Under certain conditions, entity_metadata_user_access() throws notices. I initially encountered this via the RDFx and SPARQL endpoint module, and isolated the bug to the follow piece of code:
node_load(25);
$wrapper = entity_metadata_wrapper('node', 25);
$entity = $wrapper->value();
foreach ($wrapper as $name => $property) {
if ($property->access('view')) {
// do something.
}
}
It seems that if a node has already been loaded and that you try to run entity_metadata_wrapper() and then the access() method on each of its properties, it sometimes fail when the node->uid = 0 (anonymous). to reproduce, create a node and assign the anonymous user as its author, and run the code above.
Notice: Trying to get property of non-object in entity_metadata_user_access() (line 547 of sites/all/modules/entity/modules/callbacks.inc).
Comment | File | Size | Author |
---|---|---|---|
#19 | 1237014-19-entity-user-access.patch | 2.3 KB | wodenx |
#17 | entity-create_user_test-1237014-17.patch | 4.14 KB | Mile23 |
#15 | entity-create_user_test-1237014-15.patch | 4.4 KB | Mile23 |
#14 | 1237014_op_is_create.patch | 1.63 KB | Mile23 |
#12 | 1237014_again.patch | 1.5 KB | Mile23 |
Comments
Comment #1
clemens.tolboomBoth on node#overlay=admin/config/workflow/rules and /admin/config/workflow/rules I get
Note the line # difference .. i'm unable to produce the version right now (not my system)
(this is mere a me too / subscribe)
Comment #2
fagoYep, I think this has been fixed recently. Please re-open if problems still occur with the latest version.
Comment #4
scor CreditAttribution: scor commentedI'm attaching a test so you can reproduce locally. note that it passes if the created node has
'uid' => 1
, but fails with'uid' => 0
. It seems entity_metadata_user_access() chokes on the author and reference property.Comment #5
sorin.eugen CreditAttribution: sorin.eugen commentedAttached a patch to avoid this notice by checking if entity argument is an object.
Comment #6
sorin.eugen CreditAttribution: sorin.eugen commentedAttached a patch to avoid this notice by checking if entity argument is an object and not if is set.
Comment #7
fagoThat's not the right fix, as the function signature does not allow to pass a non-entity object in. The problem is earlier when 0 is passed on as user object what fails to load.
Maybe best fix the 'getter callback' to check for that case and use drupal_anonymous_user() then. E.g. as in
Comment #8
Mile23I'm seeing this error as well, when using Inline Entity Form to potentially add users.
I haven't run through IEF to see what bugs live there, but this patch makes the message go away.
It also re-adds the fix to #1412568: entity_metadata_user_access doesn't check the status of the user :-)
Comment #10
Mile23Urgh. Passed locally.
Comment #11
scor CreditAttribution: scor commentedwrap the if condition into ( ).
please put the return on a new line (that's Drupal coding standards). you actually used that convention in the if statement above it.
Comment #12
Mile23Thanks, scor.
Comment #13
Mile23Comment #14
Mile23Same problem as #1780646: entity_access() fails to check node type specific create access if $op is create.
Comment #15
Mile23With this patch, entity_metadata_user_access() successfully handles the 'create' op, based on whether the user is blocked, and/or has 'administer users' permissions. With tests. :-)
Again, very similar to #1780646: entity_access() fails to check node type specific create access which has a patch pending as well.
Comment #17
Mile23Different tack, better solution.
Comment #18
Mile23Comment #19
wodenx CreditAttribution: wodenx commentedThis implements the approach suggested by @fago in #7, and adds @scor's test case from #4. It only addresses the notices, not the blocked user issue, and should apply independently of #17
Comment #20
fagoThanks - #19 looks good to me. Committed.