Download & Extend

Always allow entity id for EntityDrupalWrapper

Project:Entity API
Version:7.x-1.x-dev
Component:Entity property wrapper
Category:bug report
Priority:major
Assigned:Unassigned
Status:needs work

Issue Summary

entity_metadata_wrapper accepts entity id as parameter, so entity_metadata_wrapper('node', 17) lazyloads node with id 17.

This does NOT work if the entity declares a name column, like Countries does. Then a name must be given, the id won't work.

I wasn't aware of that. So was the author of organic groups 2.x.

So we have dozends of lines like

<?php
return entity_metadata_wrapper($object->group_type, $object->gid);
?>

which break for entities-with-names.

This is a general problem that always occurs if we if entity type is a variable: We can't rely on ID autoloading.
We can fix this in different ways:
1) don't use lazyloading. this will deny ease of use and merits of lazyloading for a big class uf use cases.
2) always expect id. this is the cleanest, but may break code.
3) if entity declares a name, still use id as fallback.
this will still create ambiguity for fieldless entities that use string ids but that's much less pain.

What do you think about 2) or 3)?

EDIT: i've seen that entity_load_single() says

In case the entity
* type has specified a name key, both the numeric id and the name may be
* passed.

so 3) is the way to go is uppose.

(parent issue: #1937784: Allow uppercase entity names)

Comments

#1

Title:Always allow entity id for wrapper» Always allow entity id for EntityDrupalWrapper

#2

Category:feature request» bug report
Priority:normal» major

In the light of entity_load_single() i tend to call this a major bug now and fixed it.

AttachmentSizeStatusTest resultOperations
0001-Entity-Issue-1937856-Added-Always-allow-entity-id-fo.patch1.57 KBIdleFAILED: [[SimpleTest]]: [MySQL] 271 pass(es), 10 fail(s), and 8 exception(s).View details | Re-test

#3

Status:needs review» needs work

The last submitted patch, 0001-Entity-Issue-1937856-Added-Always-allow-entity-id-fo.patch, failed testing.