Last updated September 18, 2014. Created on June 3, 2013.
Edited by reallifedigital, oadaeh, pandaPowder, nerdcore. Log in to edit this page.

Presuming you have the Entity API module installed, let's say you created an entity type called "Contact" [contact] and a bundle called 'contact_simple'.

Creating new entities is easy as:

  $entity_type = 'contact';
  $entity = entity_create($entity_type, array('type' => 'contact_simple'));
  $wrapper = entity_metadata_wrapper($entity_type, $entity);

Once the entity is created you can change its properties:

$wrapper->uid = 9;

And any attached field:

$wrapper->field_full_name->set("John doe");

Alternatively, you can set field values directly as the EntityMetadataWrapper class (provided by EntityAPI) implements PHP's magic __set() method. For example:

$wrapper->field_full_name = "John doe";

That's it. Just remember save it:


Looking for support? Visit the forums, or join #drupal-support in IRC.