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.
By AndyLicht on
Hi Forum,
i want to set a link field via entitywrapper, all my other fields are working with the following method:
$fc_item = entity_create('field_collection_item', array('field_name' => 'field_collection'));
$fc_item->setHostEntity($nodetype, $node);
$fc_wrapper = entity_metadata_wrapper('field_collection_item', $fc_item);
$fc_wrapper->{'field_link'}->set($value);
//>$fc_wrapper->{'field_md_'.$subkey}->set((array)$file);.
This works for text and numeriacl fieldtypes or files but i want to set a link. So i have tested:
$fc_wrapper->{'field_link'}->set('www.example.org'); or
$fc_wrapper->{'field_link'}->set('http://www.example.org');
but it does not work for me.
Maybe some of you can help me.
thanks a lot
Andy
Comments
In case anybody arrives here
In case anybody arrives here by google (like me), the answer is:
$fc_wrapper->{'field_link'}->set(['title' => 'Link title...', 'url' => 'http://example.com']);
Replace [] with array() above if you're running an older version of php.