EntityMetadataWrapperException: Unable to set the data property value as the parent data structure is not set. in EntityStructureWrapper->setProperty() (line 456 of /home/****/workspace/drupal/community/entity/includes/entity.wrapper.inc).

when using wrapper to set an empty node entity text (sub part of struct 'text_with_summary') you get this error.

it's because 'auto creation' is not set at this point...

in entity_metadata_field_text_property_callback() of field.info.inc you have some code to add 'auto creation' in some condition...


if (empty($instance['settings']['text_processing'])) {
      $property['property info'] =  entity_property_field_item_textsummary_info();
      // Enable auto-creation of the item, so that it is possible to just set
      // the textual or summary value.
      $property['auto creation'] = 'entity_property_create_array';
}
else {
      // For formatted text we use the type name 'text_formatted'.
      $property['type'] = ($field['cardinality'] != 1) ? 'list<text_formatted>' : 'text_formatted';
      $property['property info'] = entity_property_text_formatted_info();
    }

It seams to me that both part of "if" are array structs so $property['auto creation'] = 'entity_property_create_array'; could be put outside the "if"...

Comments

quazardous’s picture

PS : i m working on http://drupal.org/node/1033642 that is somewhat linked...

quazardous’s picture

maybe it's more in entity_metadata_node_entity_property_info_alter()


function entity_metadata_node_entity_property_info_alter(&$info) {
  // Move the body property to the node by default, as its usually there this
  // makes dealing with it more convenient.
  $info['node']['properties']['body'] = array(
    'type' => 'text_formatted',
    'label' => t('The main body text'),
    'getter callback' => 'entity_metadata_field_verbatim_get',
    'setter callback' => 'entity_metadata_field_verbatim_set',
    'property info' => entity_property_text_formatted_info(),
    'auto creation' => 'entity_property_create_array',
    'field' => TRUE,
  );
}
fago’s picture

Exactly for that to be supported, we need to add an auto-creation callback. Best, just use an callback that set ups the $item as usual but just with empty (NULL) values for the keys.

quazardous’s picture

sorry my english is so bad that i don't understand your point....

quazardous’s picture

StatusFileSize
new1.86 KB

I put a patch for this bug and #1033642.

quazardous’s picture

Status: Active » Needs review
fago’s picture

Title: EntityMetadataWrapperException: Unable to set the data property value as the parent data structure is not set. » Entity property summary doesn't support writing
Status: Needs review » Needs work

Patch looks good to me, but has some tabs in there. Please make sure to only use spaces for indention.

quazardous’s picture

Status: Needs work » Needs review
StatusFileSize
new1.86 KB

I ve done a quick sed...

quazardous’s picture

StatusFileSize
new1.86 KB
quazardous’s picture

up

fago’s picture

Status: Needs review » Fixed

thanks, committed.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.