Commit eea52300 authored by wodenx's avatar wodenx Committed by fago

Issue #1237014 by wodenx, scor, Mile23, sorin.eugen: Fixed Notices in...

Issue #1237014 by wodenx, scor, Mile23, sorin.eugen: Fixed Notices in entity_metadata_user_access() when loading an anonymous node.
parent 8de8cac1
......@@ -997,6 +997,14 @@ class EntityMetadataTestCase extends EntityWebTestCase {
// Test field level access.
$this->assertTrue($wrapper->{$this->field_name}->access('view'), 'Field access granted.');
// Create node owned by anonymous and test access() method on each of its
// properties.
$node = $this->drupalCreateNode(array('type' => 'page', 'uid' => 0));
$wrapper = entity_metadata_wrapper('node', $node->nid);
foreach ($wrapper as $name => $property) {
$property->access('view');
}
}
/**
......
......@@ -125,6 +125,9 @@ function entity_metadata_node_get_properties($node, array $options, $name, $enti
case 'edit_url':
return url('node/' . $node->nid . '/edit', $options);
case 'author':
return !empty($node->uid) ? $node->uid : drupal_anonymous_user();
}
}
......
......@@ -118,6 +118,7 @@ function entity_metadata_node_entity_property_info() {
'label' => t("Author"),
'type' => 'user',
'description' => t("The author of the node."),
'getter callback' => 'entity_metadata_node_get_properties',
'setter callback' => 'entity_property_verbatim_set',
'setter permission' => 'administer nodes',
'required' => TRUE,
......
......@@ -267,8 +267,15 @@ function entity_test_entity_getter($node) {
if (empty($node->entity)) {
$node->entity = array('type' => 'user', 'id' => $node->uid);
}
// We have to return the entity wrapped.
return entity_metadata_wrapper($node->entity['type'], $node->entity['id']);
// Special handling for anonymous user.
if ($node->entity['type'] === 'user' && empty($node->entity['id'])) {
return entity_metadata_wrapper('user', drupal_anonymous_user());
}
else {
return entity_metadata_wrapper($node->entity['type'], $node->entity['id']);
}
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment