I have create a entity type "apply" through ECK.After that i want add an "Apply" programmatically, This is my code:
global $language;
$langcode = $language->language;
$apply = new stdClass();
$apply->uid = $uid;
$apply->created = $created;
$apply->entity_type = 'apply';
$apply->type = 'apply';
$apply->bundle = 'apply';
$apply->field_resume_id[$langcode][]['target_id'] = $resume_id;
$apply->field_resume_id[$langcode][]['target_type'] = 'node';
$apply->field_job_id[$langcode][]['target_id'] = $job_id;
$apply->field_job_id[$langcode][]['target_type'] = 'node';
$apply->field_company_id[$langcode][]['target_id'] = $company_id;
$apply->field_company_id[$langcode][]['target_type'] = 'node';
entity_save('apply',$apply);
Entity reference field was not saved when the $langcode is 'zh-hans', after i change the $langcode to "und", the value was saved.
global $language;
$langcode = $language->language;
$langcode = 'und';// works
$apply = new stdClass();
$apply->uid = $uid;
$apply->created = $created;
$apply->entity_type = 'apply';
$apply->type = 'apply';
$apply->bundle = 'apply';
$apply->field_resume_id[$langcode][]['target_id'] = $resume_id;
$apply->field_resume_id[$langcode][]['target_type'] = 'node';
$apply->field_job_id[$langcode][]['target_id'] = $job_id;
$apply->field_job_id[$langcode][]['target_type'] = 'node';
$apply->field_company_id[$langcode][]['target_id'] = $company_id;
$apply->field_company_id[$langcode][]['target_type'] = 'node';
entity_save('apply',$apply);
I am not sure this is a bug of ECK or Entity reference.
Comments
Comment #1
acrazyanimal commentedI'm not 100% sure here, but it looks to me that your code is not quite right. I don't think you can have empty '[]' for both the 'target_id' and 'target_type'. You need to link them together in a single array identifier. Your code would create:
Try the following:
Regardless, I don't believe this is ECK related.
Comment #2
fmizzell commentedComment #3
fmizzell commented@acrazyanimal You've worked with multilingual sites right? Do multilingual fields work with eck?
Comment #4
fmizzell commentedComment #5
legolasboClosing old issues. Please reopen the issue with a clear description and/or steps to reproduce if this issue is still relevant.
Comment #6
legolasbo