abstract class AttributesAwareFieldableEdgeEntityBase in Apigee Edge 8
For fieldable Edge entities that can use attributes as field storage.
Hierarchy
- class \Drupal\Core\Entity\EntityBase implements EntityInterface uses RefinableCacheableDependencyTrait, DependencySerializationTrait
- class \Drupal\apigee_edge\Entity\EdgeEntityBase implements EdgeEntityInterface
- class \Drupal\apigee_edge\Entity\FieldableEdgeEntityBase implements FieldableEdgeEntityInterface uses RevisioningWorkaroundTrait
- class \Drupal\apigee_edge\Entity\AttributesAwareFieldableEdgeEntityBase implements AttributesAwareFieldableEdgeEntityBaseInterface
- class \Drupal\apigee_edge\Entity\FieldableEdgeEntityBase implements FieldableEdgeEntityInterface uses RevisioningWorkaroundTrait
- class \Drupal\apigee_edge\Entity\EdgeEntityBase implements EdgeEntityInterface
Expanded class hierarchy of AttributesAwareFieldableEdgeEntityBase
1 file declares its use of AttributesAwareFieldableEdgeEntityBase
File
- src/
Entity/ AttributesAwareFieldableEdgeEntityBase.php, line 32
Namespace
Drupal\apigee_edge\EntityView source
abstract class AttributesAwareFieldableEdgeEntityBase extends FieldableEdgeEntityBase implements AttributesAwareFieldableEdgeEntityBaseInterface {
/**
* The decorated SDK entity.
*
* @var \Apigee\Edge\Entity\EntityInterface|\Apigee\Edge\Entity\Property\AttributesPropertyInterface
*/
protected $decorated;
/**
* AttributesAwareFieldableEntityBase constructor.
*
* @param array $values
* An array of values to set, keyed by property name.
* @param null|string $entity_type
* Type of the entity. It is optional because constructor sets its default
* value.
* @param \Apigee\Edge\Entity\EntityInterface|null $decorated
* The SDK entity that this Drupal entity decorates.
*/
public function __construct(array $values, string $entity_type, ?EntityInterface $decorated = NULL) {
parent::__construct($values, $entity_type, $decorated);
if (!$this->decorated instanceof AttributesPropertyInterface) {
throw new InvalidArgumentException(sprintf('Decorated SDK entity must be instance of %s interface, got %s.', AttributesPropertyInterface::class, get_class($decorated)));
}
}
/**
* Returns the field-attribute converter service.
*
* @return \Drupal\apigee_edge\FieldAttributeConverterInterface
* Field attribute convert service.
*/
protected function fieldAttributeConverter() : FieldAttributeConverterInterface {
return \Drupal::service('apigee_edge.converter.field_attribute');
}
/**
* {@inheritdoc}
*/
public function get($field_name) {
$definition = $this
->getFieldDefinition($field_name);
// No field found with this name.
if ($definition === NULL) {
return NULL;
}
// Ignore base fields, because their value should be stored in entity
// properties.
if ($definition instanceof BaseFieldDefinition) {
return parent::get($field_name);
}
if (!isset($this->fields[$field_name])) {
/** @var \Drupal\field\Entity\FieldConfig $definition */
// Otherwise let's try to get the value of a field from an attribute
// on the decorated entity.
$value = $this
->fieldAttributeConverter()
->getFieldValueFromAttribute($this->entityTypeId, $field_name, $this->decorated
->getAttributes());
// Based on \Drupal\Core\Entity\ContentEntityBase::getTranslatedField().
/** @var \Drupal\Core\Field\FieldTypePluginManagerInterface $manager */
$manager = \Drupal::service('plugin.manager.field.field_type');
$this->fields[$field_name] = $manager
->createFieldItemList($this, $field_name, $value);
}
return $this->fields[$field_name];
}
/**
* {@inheritdoc}
*/
public function setPropertyValue(string $field_name, $value) : void {
// If value is null, parent setPropertyValue() is going to ignore it
// because SDK entity's simple property setters does not support parameters
// with null value. But if field is not a base field then we have to clear
// its value.
if ($value === NULL && !$this
->getFieldDefinition($field_name) instanceof BaseFieldDefinition) {
$this
->setAttributeValueFromField($field_name);
}
else {
try {
parent::setPropertyValue($field_name, $value);
} catch (InvalidArgumentException $e) {
// Property not found for the field, let's try to save field's value
// as an attribute.
$this
->setAttributeValueFromField($field_name);
}
}
}
/**
* Sets attribute value from a field.
*
* @param string $field_name
* Name of a field, which must not be a base field.
*/
private function setAttributeValueFromField(string $field_name) {
// We need to unaltered field data value here not the field value returned
// by $this->get($field_name)->value (magic getter).
$field_value = $this
->get($field_name)
->getValue();
// Property not found so let's save it as an attribute value.
$attribute_value = $this
->fieldAttributeConverter()
->getAttributeValueFromField($this->entityTypeId, $field_name, $field_value);
if ($attribute_value !== NULL) {
$attribute_name = $this
->fieldAttributeConverter()
->getAttributeName($field_name);
// Do not leave empty attributes. If generated attribute value is an
// empty string let's remove it from the entity.
// (Apigee Edge MGMT UI does not allow to save an entity with empty
// attribute value, the API does.)
if ($attribute_value === '') {
$this->decorated
->deleteAttribute($attribute_name);
}
else {
$this->decorated
->setAttribute($attribute_name, $attribute_value);
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AttributesAwareFieldableEdgeEntityBase:: |
protected | property |
The decorated SDK entity. Overrides EdgeEntityBase:: |
2 |
AttributesAwareFieldableEdgeEntityBase:: |
protected | function | Returns the field-attribute converter service. | |
AttributesAwareFieldableEdgeEntityBase:: |
public | function |
Gets a field item list. Overrides FieldableEdgeEntityBase:: |
1 |
AttributesAwareFieldableEdgeEntityBase:: |
private | function | Sets attribute value from a field. | |
AttributesAwareFieldableEdgeEntityBase:: |
public | function |
Updates the property value on an entity by field name. Overrides FieldableEdgeEntityBase:: |
|
AttributesAwareFieldableEdgeEntityBase:: |
public | function |
AttributesAwareFieldableEntityBase constructor. Overrides EdgeEntityBase:: |
2 |
CacheableDependencyTrait:: |
protected | property | Cache contexts. | |
CacheableDependencyTrait:: |
protected | property | Cache max-age. | |
CacheableDependencyTrait:: |
protected | property | Cache tags. | |
CacheableDependencyTrait:: |
protected | function | Sets cacheability; useful for value object constructors. | |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | Aliased as: traitSleep | 1 |
DependencySerializationTrait:: |
public | function | 2 | |
EdgeEntityBase:: |
public static | function |
Creates a Drupal entity from an SDK Entity. Overrides EdgeEntityInterface:: |
|
EdgeEntityBase:: |
public | function |
Returns the decorated SDK entity. Overrides EdgeEntityInterface:: |
2 |
EdgeEntityBase:: |
abstract protected static | function | The FQCN of the decorated class from the PHP API Client. | 5 |
EdgeEntityBase:: |
abstract protected | function | Return the entity id used in Drupal. | 4 |
EdgeEntityBase:: |
public | function | ||
EdgeEntityBase:: |
public | function | ||
EdgeEntityBase:: |
public | function |
We have to override this to make it compatible with the SDK's
entity interface that enforces the return type. Overrides EntityBase:: |
5 |
EdgeEntityBase:: |
public | function | ||
EdgeEntityBase:: |
public | function |
Gets the label of the entity. Overrides EntityBase:: |
2 |
EdgeEntityBase:: |
public static | function |
Returns all unique ids how an entity can be referenced in Apigee Edge. Overrides EdgeEntityInterface:: |
2 |
EdgeEntityBase:: |
public | function |
List of unique ids how an entity can be referenced in Apigee Edge. Overrides EdgeEntityInterface:: |
|
EntityBase:: |
protected | property | Boolean indicating whether the entity should be forced to be new. | |
EntityBase:: |
protected | property | The entity type. | |
EntityBase:: |
protected | property | A typed data object wrapping this entity. | |
EntityBase:: |
public | function |
Checks data value access. Overrides AccessibleInterface:: |
1 |
EntityBase:: |
public | function |
Gets the bundle of the entity. Overrides EntityInterface:: |
1 |
EntityBase:: |
public static | function |
Constructs a new entity object, without permanently saving it. Overrides EntityInterface:: |
|
EntityBase:: |
public | function |
Creates a duplicate of the entity. Overrides EntityInterface:: |
2 |
EntityBase:: |
public | function |
Deletes an entity permanently. Overrides EntityInterface:: |
2 |
EntityBase:: |
public | function |
Enforces an entity to be new. Overrides EntityInterface:: |
|
EntityBase:: |
protected | function | Gets the entity manager. | |
EntityBase:: |
protected | function | Gets the entity type bundle info service. | |
EntityBase:: |
protected | function | Gets the entity type manager. | |
EntityBase:: |
public | function |
The cache contexts associated with this object. Overrides CacheableDependencyTrait:: |
|
EntityBase:: |
public | function |
The maximum age for which this object may be cached. Overrides CacheableDependencyTrait:: |
|
EntityBase:: |
public | function |
The cache tags associated with this object. Overrides CacheableDependencyTrait:: |
|
EntityBase:: |
public | function |
Returns the cache tags that should be used to invalidate caches. Overrides EntityInterface:: |
2 |
EntityBase:: |
public | function |
Gets the key that is used to store configuration dependencies. Overrides EntityInterface:: |
|
EntityBase:: |
public | function |
Gets the configuration dependency name. Overrides EntityInterface:: |
1 |
EntityBase:: |
public | function |
Gets the configuration target identifier for the entity. Overrides EntityInterface:: |
1 |
EntityBase:: |
public | function |
Gets the entity type definition. Overrides EntityInterface:: |
|
EntityBase:: |
public | function |
Gets the ID of the type of the entity. Overrides EntityInterface:: |
|
EntityBase:: |
protected | function | The list cache tags to invalidate for this entity. | |
EntityBase:: |
public | function |
Gets the original ID. Overrides EntityInterface:: |
1 |
EntityBase:: |
public | function |
Gets a typed data object for this entity object. Overrides EntityInterface:: |
|
EntityBase:: |
public | function |
Indicates if a link template exists for a given key. Overrides EntityInterface:: |
|
EntityBase:: |
protected static | function | Invalidates an entity's cache tags upon delete. | 1 |
EntityBase:: |
protected | function | Invalidates an entity's cache tags upon save. | 1 |
EntityBase:: |
public | function |
Determines whether the entity is new. Overrides EntityInterface:: |
2 |
EntityBase:: |
public | function |
Gets the language of the entity. Overrides EntityInterface:: |
1 |
EntityBase:: |
protected | function | Gets the language manager. | |
EntityBase:: |
public | function |
Deprecated way of generating a link to the entity. See toLink(). Overrides EntityInterface:: |
1 |
EntityBase:: |
protected | function | Gets an array link templates. | 1 |
EntityBase:: |
public static | function |
Loads an entity. Overrides EntityInterface:: |
|
EntityBase:: |
public static | function |
Loads one or more entities. Overrides EntityInterface:: |
|
EntityBase:: |
public | function |
Acts on a created entity before hooks are invoked. Overrides EntityInterface:: |
4 |
EntityBase:: |
public static | function |
Acts on deleted entities before the delete hook is invoked. Overrides EntityInterface:: |
16 |
EntityBase:: |
public static | function |
Acts on loaded entities. Overrides EntityInterface:: |
2 |
EntityBase:: |
public static | function |
Changes the values of an entity before it is created. Overrides EntityInterface:: |
5 |
EntityBase:: |
public static | function |
Acts on entities before they are deleted and before hooks are invoked. Overrides EntityInterface:: |
4 |
EntityBase:: |
public | function |
Acts on an entity before the presave hook is invoked. Overrides EntityInterface:: |
2 |
EntityBase:: |
public | function |
Gets a list of entities referenced by this entity. Overrides EntityInterface:: |
1 |
EntityBase:: |
public | function |
Saves an entity permanently. Overrides EntityInterface:: |
3 |
EntityBase:: |
public | function |
Sets the original ID. Overrides EntityInterface:: |
1 |
EntityBase:: |
public | function |
Generates the HTML for a link to this entity. Overrides EntityInterface:: |
|
EntityBase:: |
public | function |
Gets the URL object for the entity. Overrides EntityInterface:: |
2 |
EntityBase:: |
public | function |
Gets a list of URI relationships supported by this entity. Overrides EntityInterface:: |
|
EntityBase:: |
public | function |
Gets the public URL for this entity. Overrides EntityInterface:: |
2 |
EntityBase:: |
public | function |
Gets the URL object for the entity. Overrides EntityInterface:: |
1 |
EntityBase:: |
protected | function | Gets an array of placeholders for this entity. | 2 |
EntityBase:: |
public | function |
Gets the entity UUID (Universally Unique Identifier). Overrides EntityInterface:: |
1 |
EntityBase:: |
protected | function | Gets the UUID generator. | |
FieldableEdgeEntityBase:: |
protected | property | Local cache for field definitions. | |
FieldableEdgeEntityBase:: |
protected | property | Local cache for for fields. | |
FieldableEdgeEntityBase:: |
protected | property | Whether entity validation was performed. | |
FieldableEdgeEntityBase:: |
protected | property | Whether entity validation is required before saving the entity. | |
FieldableEdgeEntityBase:: |
public static | function |
Provides base field definitions for an entity type. Overrides FieldableEntityInterface:: |
2 |
FieldableEdgeEntityBase:: |
public static | function |
Provides field definitions for a specific bundle. Overrides FieldableEntityInterface:: |
|
FieldableEdgeEntityBase:: |
protected | function | Converts a field value to a property value. | |
FieldableEdgeEntityBase:: |
private static | function | Returns whether an entity property is blacklisted to be exposed as field. | |
FieldableEdgeEntityBase:: |
protected static | function | Attempts to create a base field definition from a type. | |
FieldableEdgeEntityBase:: |
public | function |
Gets the definition of a contained field. Overrides FieldableEntityInterface:: |
|
FieldableEdgeEntityBase:: |
public | function |
Gets an array of field definitions of all contained fields. Overrides FieldableEntityInterface:: |
|
FieldableEdgeEntityBase:: |
public | function |
Gets an array of all field item lists. Overrides FieldableEntityInterface:: |
|
FieldableEdgeEntityBase:: |
protected | function | Returns the field value from the current object. | |
FieldableEdgeEntityBase:: |
public | function | ||
FieldableEdgeEntityBase:: |
protected static | function | Parses the properties and its types from the parent class. | |
FieldableEdgeEntityBase:: |
public | function |
Gets an array of field item lists for translatable fields. Overrides FieldableEntityInterface:: |
|
FieldableEdgeEntityBase:: |
public | function |
Determines whether the entity has a field with the given name. Overrides FieldableEntityInterface:: |
|
FieldableEdgeEntityBase:: |
public | function |
Checks whether entity validation is required before saving the entity. Overrides FieldableEntityInterface:: |
|
FieldableEdgeEntityBase:: |
public | function |
Reacts to changes to a field. Overrides FieldableEntityInterface:: |
|
FieldableEdgeEntityBase:: |
public | function |
Acts on a saved entity before the insert or update hook is invoked. Overrides EntityBase:: |
|
FieldableEdgeEntityBase:: |
private static | function | Returns the type of the field that should represent an entity property. | |
FieldableEdgeEntityBase:: |
protected static | function | Array of properties that should not be exposed as base fields by default. | 2 |
FieldableEdgeEntityBase:: |
protected static | function | Static mapping between entity properties and Drupal field types. | 2 |
FieldableEdgeEntityBase:: |
public | function |
Sets a field value. Overrides FieldableEntityInterface:: |
1 |
FieldableEdgeEntityBase:: |
public | function |
Sets whether entity validation is required before saving the entity. Overrides FieldableEntityInterface:: |
|
FieldableEdgeEntityBase:: |
public | function |
Gets an array of all property values. Overrides EntityBase:: |
|
FieldableEdgeEntityBase:: |
public | function |
Validates the currently set values. Overrides FieldableEntityInterface:: |
|
FieldableEdgeEntityBase:: |
public | function |
Overrides EntityBase:: |
|
RefinableCacheableDependencyTrait:: |
public | function | 1 | |
RefinableCacheableDependencyTrait:: |
public | function | ||
RefinableCacheableDependencyTrait:: |
public | function | ||
RefinableCacheableDependencyTrait:: |
public | function | ||
RevisioningWorkaroundTrait:: |
public | function | ||
RevisioningWorkaroundTrait:: |
public | function | ||
RevisioningWorkaroundTrait:: |
public | function | ||
RevisioningWorkaroundTrait:: |
public | function | ||
RevisioningWorkaroundTrait:: |
public | function | ||
RevisioningWorkaroundTrait:: |
public | function | ||
RevisioningWorkaroundTrait:: |
public | function | ||
RevisioningWorkaroundTrait:: |
public | function | ||
RevisioningWorkaroundTrait:: |
public | function |