class ECKEntity in Entity Construction Kit (ECK) 7.3
Same name and namespace in other branches
- 7 eck.module \EckEntity
- 7.2 eck.module \ECKEntity
Hierarchy
- class \Entity implements EntityInterface
- class \ECKEntity
Expanded class hierarchy of ECKEntity
2 string references to 'ECKEntity'
- eck_permissions_eck_access in modules/
eck_permissions/ eck_permissions.module - eck__entity_type__info in ./
eck.entity_type.inc - Generate the entity info for a specific entity.
File
- ./
eck.classes.inc, line 765 - Classes for all the different objects used in ECK.
View source
class ECKEntity extends Entity {
// This flag only gets set so we can make our properties public again
// before we save the object.
protected $ignoreValidation;
protected $PropertyValues = array();
/**
* Constructor.
*/
public function __construct(array $values = array(), $entity_type = NULL) {
$this->ignoreValidation = FALSE;
parent::__construct($values, $entity_type);
// I have this stupid crap.. fixing drupals mess ups.
$entity_type_name = $this
->entityType();
$entity_type = EntityType::loadByName($entity_type_name);
$properties = $entity_type->properties;
$property_names = array_keys($properties);
foreach ($property_names as $pn) {
$value = $this->{$pn};
unset($this->{$pn});
$this->{$pn} = $value;
}
}
/**
* Magic set.
*/
public function __set($name, $value) {
// Lets implement non restrictive validation.
// If it is a property validate, if it isn't just set it.
// Try to load the entityType and property information.
if ($entity_type_name = $this
->entityType()) {
if (($entity_type = EntityType::loadByName($entity_type_name)) && is_object($entity_type)) {
if ($properties = $entity_type->properties) {
$property_names = array_keys($properties);
}
}
}
// @todo should look into loading the entity info through entity_get_info()
// and determining validation that way.
// Currently we don't validate when the ECKEntityType has not been
// instantiated yet. Not sure if it is needed though.
if (isset($property_names) && in_array($name, $property_names) && !$this->ignoreValidation) {
$property_type = $properties[$name]['type'];
$property_type_class = eck_get_property_type_class($property_type);
if (!isset($value)) {
$schema = $property_type_class::schema();
if (isset($schema['default'])) {
$this->PropertyValues[$name] = $schema['default'];
}
}
elseif ($property_type_class::validate($value)) {
$this->PropertyValues[$name] = $value;
}
else {
throw new Exception("Invalid value {$value} for property {$name} of type {$property_type} in\n Entity type: {$entity_type_name}");
}
}
else {
$this->{$name} = $value;
}
}
/**
* Magic get.
*/
public function __get($name) {
if (array_key_exists($name, $this->PropertyValues)) {
return $this->PropertyValues[$name];
}
elseif (isset($this->{$name})) {
return $this->{$name};
}
elseif ($field = field_info_field($name)) {
if ($this->entityType) {
if ($bundle = $this
->bundle()) {
if (in_array($bundle, $field['bundles'][$this->entityType])) {
$this->{$name} = array();
return $this->{$name};
}
}
}
}
return NULL;
}
/**
* Magic set.
*/
public function __isset($name) {
if (array_key_exists($name, $this->PropertyValues)) {
return TRUE;
}
elseif (isset($this->{$name})) {
return TRUE;
}
return FALSE;
}
/**
* Save.
*/
public function save() {
// Going back to public properties.
$this->ignoreValidation = TRUE;
foreach ($this->PropertyValues as $property => $value) {
$this->{$property} = $value;
}
return parent::save();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ECKEntity:: |
protected | property | ||
ECKEntity:: |
protected | property | ||
ECKEntity:: |
public | function |
Save. Overrides Entity:: |
|
ECKEntity:: |
public | function |
Constructor. Overrides Entity:: |
|
ECKEntity:: |
public | function | Magic get. | |
ECKEntity:: |
public | function | Magic set. | |
ECKEntity:: |
public | function | Magic set. | |
Entity:: |
protected | property | 1 | |
Entity:: |
protected | property | ||
Entity:: |
protected | property | ||
Entity:: |
protected | property | ||
Entity:: |
protected | property | ||
Entity:: |
public | function |
Builds a structured array representing the entity's content. Overrides EntityInterface:: |
1 |
Entity:: |
public | function |
Returns the bundle of the entity. Overrides EntityInterface:: |
|
Entity:: |
protected | function | Defines the entity label if the 'entity_class_label' callback is used. | 1 |
Entity:: |
protected | function | Override this in order to implement a custom default URI and specify 'entity_class_uri' as 'uri callback' hook_entity_info(). | |
Entity:: |
public | function |
Permanently deletes the entity. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Returns the info of the type of the entity. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Returns the type of the entity. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Exports the entity. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Gets the raw, translated value of a property or field. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Checks if the entity has a certain exportable status. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Returns the entity identifier, i.e. the entities name or numeric id. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Returns the internal, numeric identifier. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Checks whether the entity is the default revision. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Returns the label of the entity. Overrides EntityInterface:: |
|
Entity:: |
protected | function | Set up the object instance on construction or unserializiation. | |
Entity:: |
public | function |
Returns the uri of the entity just as entity_uri(). Overrides EntityInterface:: |
|
Entity:: |
public | function |
Generate an array for rendering the entity. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Returns the EntityMetadataWrapper of the entity. Overrides EntityInterface:: |
|
Entity:: |
public | function | Magic method to only serialize what's necessary. | |
Entity:: |
public | function | Magic method to invoke setUp() on unserialization. |