The background of this question is that I'm trying to migrate data from Drupal 6 Imagefield Extended to Drupal 7 File Entity (with File Entity Inline). See also https://www.drupal.org/node/974888
First I tried to understand how entities work and how they can be extracted and manipulated using Entity Metadata Wrappers. That seems to work ok, for example, I can get the values of my imagefield like this:
$nid = 103025;
$node_wrapper = entity_metadata_wrapper('node', $nid);
$images = $node_wrapper->field_image->value();
And it seems that I could change the values of the images with something like this:
// Do something with $images
$node_wrapper->field_image->set($images);
$node_wrapper->revision->set(1);
$node_wrapper->save();
(For some reason it's not saving the values for the node in my case, but that's another question.)
My problem now is that I have nested fields, i.e. the imagefield has "subfields" for the source and license (that I had added in Drupal 6 using Imagefield Extended). I do get the values of those nested fields in $images - but only in the typical array with $images[und][0]['value']
and $images[und][0]['safe_value']
. But there seems to be no way to get those values through the wrapper, for example like
$node_wrapper->field_image->field_source->value();
$node_wrapper->field_image->value()->field_source->value();
Now I have been trying for hours to figure out how I can change (or populate) those (sub) fields and then save the entire node, but to no avail.
I'm also wondering if it's necessary to do this on a node level as files are also entities, but it seems that there is nothing like entity_metadata_wrapper('file', $fid);
.
I'd appreciate any hint that could point me in the right direction because the search has been kind of exhausting.
$node_wrapper->field_image->file->field_source->value()
?$node_wrapper->field_image->getPropertyInfo()
and$node_wrapper->field_image->file->getPropertyInfo()
to see what fields/properties the system things are available. That might help to shed some light. Feel free to edit them into the question and ping me if you want me to have a look$node_wrapper->field_image[0]->getPropertyInfo()
? And then perhaps$node_wrapper->field_image[0]->file->getPropertyInfo()
. I don't have file entity installed on anything so I'm guessing a bit