abstract class Entity extends stdClass implements EntityInterface {
public $is_active_revision = TRUE;
public function __construct(array $values = array()) {
foreach ($values as $key => $value) {
$this->$key = $value;
}
}
public function isNew() {
return !empty($this->is_new) || !$this->id();
}
public function bundle() {
return $this->entityType();
}
public function label() {
$entity_info = entity_get_info($this->entityType());
$label = NULL;
if (isset($entity_info['label callback'])) {
$label = call_user_func($entity_info['label callback'], $this);
}
else if (isset($entity_info['entity keys']['label'])) {
$label = $this->{$entity_info['entity keys']['label']};
}
return $label;
}
public static function createAccess($bundle = NULL, $account = NULL) {
return TRUE;
}
public function access($op, $account = NULL) {
return TRUE;
}
public function save() {
return entity_get_controller($this->entityType())->save($this);
}
public function delete() {
if (!$this->isNew()) {
entity_get_controller($this->entityType())->delete(array($this->id()));
}
}
public function buildContent($view_mode = 'full', $langcode = NULL) {
return entity_get_controller($this->entityType())->buildContent($this, $view_mode, $langcode);
}
public function view($view_mode = 'full', $langcode = NULL, $page = NULL) {
$view = entity_get_controller($this->entityType())->view(array($this->id() => $this), $view_mode, $langcode, $page);
return $view[$this->entityType()][$this->id()];
}
public function createDuplicate() {
$entity_info = entity_get_info($this->entityType());
$duplicate = clone $this;
$duplicate->{$entity_info['entity keys']['id']} = NULL;
if (isset($entity_info['entity_keys']['revision'])) {
$duplicate->{$entity_info['entity keys']['revision']} = NULL;
}
return $duplicate;
}
public function getFieldValue($field_name, $value_key = 'value', $langcode = NULL) {
$values = $this->getFieldValues($field_name, $value_key, $langcode);
return empty($values) ? NULL : reset($values);
}
public function getFieldValues($field_name, $value_key = 'value', $langcode = NULL) {
$values = array();
if ($field_items = field_get_items($this->entityType(), $this, $field_name, $langcode)) {
foreach ($field_items as $item) {
if (isset($item[$value_key])) {
$values[] = $item[$value_key];
}
}
}
return $values;
}
public function getRevisionId() {
return NULL;
}
public function isActiveRevision() {
return $this->is_active_revision;
}
public function setIsActiveRevision() {
$this->is_active_revision = TRUE;
}
}