protected function EntityDrupalWrapper::setEntity in Entity API 7
Sets the entity internally accepting both the entity id and object.
2 calls to EntityDrupalWrapper::setEntity()
- EntityDrupalWrapper::set in includes/
entity.wrapper.inc  - Overridden to support setting the entity by either the object or the id.
 - EntityDrupalWrapper::value in includes/
entity.wrapper.inc  - Overridden.
 
File
- includes/
entity.wrapper.inc, line 628  - Provides wrappers allowing easy usage of the entity metadata.
 
Class
- EntityDrupalWrapper
 - Provides a wrapper for entities registrered in hook_entity_info().
 
Code
protected function setEntity($data) {
  // For entities we allow getter callbacks to return FALSE, which we
  // interpret like NULL values as unset properties.
  if (isset($data) && $data !== FALSE && !is_object($data)) {
    $this->id = $data;
    $this->data = FALSE;
  }
  elseif (is_object($data) && $data instanceof EntityDrupalWrapper) {
    // We got a wrapped entity passed, so take over its values.
    $this->id = $data->id;
    $this->data = $data->data;
    // For generic entity references, also update the entity type accordingly.
    if ($this->info['type'] == 'entity') {
      $this->type = $data->type;
    }
  }
  elseif (is_object($data)) {
    // We got the entity object passed.
    $this->data = $data;
    $id = entity_id($this->type, $data);
    $this->id = isset($id) ? $id : FALSE;
  }
  else {
    $this->id = FALSE;
    $this->data = NULL;
  }
}