You are here

public function EntityDrupalWrapper::save in Entity API 7

Permanently save the wrapped entity.

Return value

EntityDrupalWrapper

Throws

EntityMetadataWrapperException If the entity type does not support saving.

File

includes/entity.wrapper.inc, line 887
Provides wrappers allowing easy usage of the entity metadata.

Class

EntityDrupalWrapper
Provides a wrapper for entities registrered in hook_entity_info().

Code

public function save() {
  if ($this->data) {
    if (!entity_type_supports($this->type, 'save')) {
      throw new EntityMetadataWrapperException("There is no information about how to save entities of type " . check_plain($this->type) . '.');
    }
    entity_save($this->type, $this->data);

    // On insert, update the identifier afterwards.
    if (!$this->id) {
      list($this->id, , ) = entity_extract_ids($this->type, $this->data);
    }
  }

  // If the entity hasn't been loaded yet, don't bother saving it.
  return $this;
}