Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 293238

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

$
0
0

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.

<?php
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):

<?php
$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>');
?>

Viewing all articles
Browse latest Browse all 293238

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>