Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I can create an unsaved ECK entity using entity_create(), then do entity_view() on it to render the fields and such.
But, it throws notices:
Notice: Undefined property: Entity::$id in eck_entity_view_alter() (line 860 of /vagrant/www/ethos7/sites/all/modules/contrib/eck/eck.module).
Notice: Undefined property: Entity::$id in eck__entity__view_callback() (line 517 of /vagrant/www/ethos7/sites/all/modules/contrib/eck/eck.entity.inc).
Notice: Undefined property: Entity::$id in eck__entity__view_callback() (line 522 of /vagrant/www/ethos7/sites/all/modules/contrib/eck/eck.entity.inc).
The notices go away, if you add
$entity->id = NULL;
The entity renders fine with or without it.
Example:
$entity = entity_create('exhibitor_registration', $product->data['exhibitor_registration']);
// Following line is needed so we can render an unsaved entity.
// https://www.drupal.org/node/2421623
$entity->id = NULL;
entity_view('exhibitor_registration', array($entity));
Comments
Comment #1
djdevinComment #2
eric.napier CreditAttribution: eric.napier at CivicActions commentedThere seems to be precedent in contrib for including entity ID of NULL for this case of creating an unsaved entity: http://www.drupalcontrib.org/api/drupal/contributions!commerce_cardonfil.... I do not believe this is an issue with ECK per say, but more to do with proper interface with Entity API, the module that defines entity_create(). These notices from ECK in this case I believe are valid, I suggest adding the NULL value to your code in order to avoid them.