0

I'm using entity_metadata_wrapper to programatically create some nodes. I noticed that some of the fields weren't showing in the node/edit form after doing this, even though they are shown on the frontend. After lots of digging I found in the database that the field data is being saved with 'und' instead of my chosen language ('en'). What is the way to fix this?

The field 'introduction' is definitely translatable before anyone asks (otherwise it would show in the backend just fine).

$entity = entity_create('node', array(
    'type' => 'my_bundle',
    'uid' => $user->uid,
    'status' => 1,
    'comment' => 0,
    'promote' => 0,
    'language' => 'en'
  ));

$ewrapper = entity_metadata_wrapper('node', $entity);
$ewrapper->language('en'); // Thought this would do it, but no dice
$ewrapper->title->set('This works fine');
$ewrapper->field_introduction->set('This doesnt');
$ewrapper->save();
0

Test the following described here:

$ewrapper = entity_metadata_wrapper('node', $entity, [
  'langcode' => 'en',
]);

instead of

$ewrapper->language('en');
  • Nice try, but makes no difference – Chris Jun 5 '17 at 9:18

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.