abstract class EntityBase in Realistic Dummy Content 8
Generic entity manipulator.
Class with an abstract Modify() method. Subclasses can have access to entities in order to override demo content in them.
Hierarchy
- class \Drupal\realistic_dummy_content_api\manipulators\Base
- class \Drupal\realistic_dummy_content_api\manipulators\EntityBase
Expanded class hierarchy of EntityBase
1 file declares its use of EntityBase
- FieldModifier.php in api/
src/ manipulators/ FieldModifier.php - Define autoload class.
File
- api/
src/ manipulators/ EntityBase.php, line 20 - Define autoload class.
Namespace
Drupal\realistic_dummy_content_api\manipulatorsView source
abstract class EntityBase extends Base {
private $hash;
private $entity;
private $type;
/**
* Constructor.
*
* @param $entity
* The entity object.
* @param $type
* The entity type of the object, for example user or node.
*/
function __construct($entity, $type) {
$this->entity = $entity;
$this->hash = md5(serialize($entity));
$this->type = $type;
}
/**
* Getter for the entity.
*
* @return
* An entity object, for example \Drupal\node\Entity\Node
*/
function GetEntity() {
return $this->entity;
}
/**
* Getter for the hash which uniquely identifies this entity.
*/
function GetHash() {
return $this->hash;
}
/**
* Updates the entity object.
*
* Used by functions which manipulate fields and properties. Once they
* are done with the manipulations, they update the entity using this
* function.
*/
function SetEntity($entity) {
$this->entity = $entity;
}
/**
* Get the entity type of the entity being manipulated.
*
* All entities must have a type and a bundle. The type can be node,
* user, etc. and the bundle can be article, page. In case of a user,
* there must be a bundle even if there is only one: it is called user,
* like the entity type.
*
* @return
* The entity type, for example "node" or "user".
*/
function GetType() {
$return = $this->type
->get('id');
return $return;
}
/**
* Get the bundle of the entity being manipulated.
*
* All entities must have a type and a bundle. The type can be node,
* user, etc. and the bundle can be article, page. In case of a user,
* there must be a bundle even if there is only one: it is called user,
* like the entity type.
*
* @return
* The bundle, for example "article" or "user". Is a bundle is not
* readily available, return the entity type.
*/
function GetBundle() {
$entity = $this
->GetEntity();
$type = $entity
->getType();
if ($type) {
$return = $type;
}
else {
$return = $this
->GetType();
}
if (!is_string($return)) {
throw new Exception('EntityBase::GetBundle() internal error, not returning a string');
}
return $return;
}
/**
* Modify the entity.
*
* Subclasses of EntityBase need to override
* this function to perform modifications on the entity.
*/
abstract function Modify();
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Base:: |
function | |||
EntityBase:: |
private | property | ||
EntityBase:: |
private | property | ||
EntityBase:: |
private | property | ||
EntityBase:: |
function | Get the bundle of the entity being manipulated. | ||
EntityBase:: |
function | Getter for the entity. | ||
EntityBase:: |
function | Getter for the hash which uniquely identifies this entity. | ||
EntityBase:: |
function | Get the entity type of the entity being manipulated. | ||
EntityBase:: |
abstract | function | Modify the entity. | 1 |
EntityBase:: |
function | Updates the entity object. | ||
EntityBase:: |
function | Constructor. |