I tried:

  $entity_info = entity_get_info($entity_type);
  $entity = entity_create($entity_type, array(
    $entity_info['entity keys']['bundle'] => $bundle_name,
    $entity_info['entity keys']['label'] => $label,
  entity_save($entity_type, $entity);

But it didn't work (terms were created with vid = 0). Should it work? If so, here's a patch.

entity_metadata_taxonomy_term_save.patch1.57 KBJohn Morahan
PASSED: [[SimpleTest]]: [MySQL] 325 pass(es). View


fago’s picture

Status: Needs review » Closed (works as designed)

Well, that's how taxonomy module does it. It's not our job to fix it. I guess providing the 'vid' at creation time should work.

Still, there is entity_property_values_create_entity() which gives you a uniform interface for creating entities based upon property values.