You are here

public function Entity::wrapper in Entity API 7

Returns the EntityMetadataWrapper of the entity.

Return value

EntityDrupalWrapper An EntityMetadataWrapper containing the entity.

Overrides EntityInterface::wrapper

File

includes/entity.inc, line 262
Provides a base class for entities.

Class

Entity
A common class for entities.

Code

public function wrapper() {
  if (empty($this->wrapper)) {
    $this->wrapper = entity_metadata_wrapper($this->entityType, $this);
  }
  elseif ($this->wrapper
    ->value() !== $this) {

    // Wrapper has been modified outside, so let's better create a new one.
    $this->wrapper = entity_metadata_wrapper($this->entityType, $this);
  }
  return $this->wrapper;
}