EntityWrapper::getValue() currently doesn't work with unsaved entities.

Created on 6 February 2013, almost 12 years ago
Updated 29 July 2014, over 10 years ago

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>');
πŸ› Bug report
Status

Closed: duplicate

Version

8.0 ⚰️

Component
EntityΒ  β†’

Last updated about 6 hours ago

Created by

πŸ‡¦πŸ‡ΉAustria fubhy

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States bkline Virginia

    @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?

Production build 0.71.5 2024