1

I'm looking for a solution to my problem that is pretty simple in fact. I'm on an importing task in which I have to create programmatically a node and then populate all its fields.

As we're using the Scald module, we can add several medias to a node. But I can't figure out how to associate several medias to a node ?

I tried the following :

foreach ($file_atoms as $i => $atom) {
    $node_wrapper->field_atom[$i] = $atom->sid;
}

or :

foreach ($file_atoms as $i => $atom) {
    $node_wrapper->field_atom[$i]->set($atom->sid);
}

But I get the following error :

Error: Cannot use object of type EntityDrupalWrapper as array

I followed the doc on this page but it does not seems to work..

Can somebody help me ?

I'm encountering the same problem with taxonomies : I'm not able to set multiple values to the node wrapper.

  • Are you sure the field_atom field has the option of taking multiple medias? – Florian Margaine Oct 14 '14 at 7:46
  • Good question, the field is not configured for several medias... Thanks – Seb Oct 14 '14 at 8:37
0

Your issue is that your field_atom field is not configured as multiple.

When it's not, an EntityDrupalWrapper object will give you direct access to the field, instead of having to go through the 0 delta.

Just fix the field_atom options to accept multiple medias, and your code will work fine.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.