Skip to content

Instantly share code, notes, and snippets.

@mrded
Last active December 24, 2015 16:09
Show Gist options
  • Save mrded/6825450 to your computer and use it in GitHub Desktop.
Save mrded/6825450 to your computer and use it in GitHub Desktop.
Drupal: Example of creating field_collection item.
<?php
$entity = entity_create('field_collection_item', array('field_name' => 'field_education'));
$entity->profile_university_term[LANGUAGE_NONE][]['tid'] = _wj_users_reg_add_tag('university', $values);
$entity->profile_degree_term[LANGUAGE_NONE][]['tid'] = _wj_users_reg_add_tag('degree', $values);
$entity->profile_first_year[LANGUAGE_NONE][]['value'] = format_date($first_year_time, 'custom', 'Y-m-d H:i:s');
$entity->profile_graduation_year[LANGUAGE_NONE][]['value'] = format_date($graduation_year_time, 'custom', 'Y-m-d H:i:s');
$entity->setHostEntity('profile2', $profile);
$entity->save();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment