Currently, EntityWrapper::getValue() relies on entity_load() and returns NULL if the entity hasn't been saved yet. This should be considered a bug because we need this to work with unsaved entities as well e.g. when passing a freshly created node object before saving it.
public function getValue() {
$source = $this->getIdSource();
$id = $source ? $source->getValue() : $this->id;
return $id ? entity_load($this->entityType, $id) : NULL;
}
Originally reported by EclipseGc (following snippet currently fails):
$node = entity_create('node', array('type' => 'page'));
$typed_data = typed_data()->create(
array(
'type' => 'entity',
'constraints' => array(
'EntityType' => 'node',
),
),
$node
);
drupal_set_message('<pre>' . var_export($typed_data->getValue(), TRUE) . '</pre>');
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | 1909666-11.patch | 2.46 KB | podarok |
| #8 | 1909666-8.patch | 923 bytes | podarok |
| #6 | 1909666-5.patch | 924 bytes | podarok |
| #4 | drupal-getValue_on_unsaved_entities-1909666-4.patch | 1021 bytes | maciej.zgadzaj |
Comments
Comment #1
fagoLet's make sure to consider this when doing #1868004: Improve the TypedData API usage of EntityNG.
Comment #1.0
fubhy commentedUpdating issue summary.
Comment #2
fubhy commentedSimplifying issue title.
Comment #3
eclipsegc commentedDoes this seem saner?
Eclipse
Comment #4
maciej.zgadzaj commentedRolled into patch. Ping testbot.
Comment #6
podarokupdate
bot?
Comment #8
podarokwoops
Comment #9
podarokcross post
Comment #11
podarokthis should fix a few tests
Comment #12.0
(not verified) commentedUpdated issue summary.
Comment #13
berdirI think this works fine now.
Comment #14
bkline@berdir This issue was marked as a duplicate, but I can't find any identification of the other ticket of which this one was deemed to be a duplicate. Is it there and I just missed it?