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.
Hi - Doing something like:
$newnode = entity_create('node', array(
'type' => 'participant',
'nid' => 0,
'uid' => $uid,
));
$participant_wrapper = entity_metadata_wrapper('node', $newnode);
I expected that $participant_wrapper->field_some_field->value() would have all the fields defined by the bundle with their default values set, but not so. Is there a recommended way to set field defaults for creation of a new entity? Does it involve explicitly iterating over all the fields attached to that bundle, looking up their field definitions, and applying individually?
Thanks
-Bronius
Comments
Comment #2
farald CreditAttribution: farald as a volunteer commentedAlso interested in this, it seems cumbersome to replicate each and every one of the default values when creating a new entity.
Comment #3
farald CreditAttribution: farald as a volunteer commentedFirst get the field instances, then apply the default values using that information.
Here's how you get the default values, assuming you have just created a basic node object $node:
Comment #4
farald CreditAttribution: farald as a volunteer commented