abstract class App in Apigee Edge 8
Base class for App Drupal entities.
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\App implements AppInterface
- 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 App
1 file declares its use of App
- TeamApp.php in modules/
apigee_edge_teams/ src/ Entity/ TeamApp.php
2 string references to 'App'
- apigee_edge.developer_app_settings.yml in config/
install/ apigee_edge.developer_app_settings.yml - config/install/apigee_edge.developer_app_settings.yml
- DeveloperAppAliasForm::originalSingularLabel in src/
Form/ DeveloperAppAliasForm.php - Returns the original singular label of the entity.
File
- src/
Entity/ App.php, line 33
Namespace
Drupal\apigee_edge\EntityView source
abstract class App extends AttributesAwareFieldableEdgeEntityBase implements AppInterface {
/**
* The decorated app entity from the SDK.
*
* @var \Apigee\Edge\Api\Management\Entity\AppInterface
*/
protected $decorated;
/**
* App 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, ?EdgeEntityInterface $decorated = NULL) {
// Credentials should not be cached.
unset($values['credentials']);
/** @var \Apigee\Edge\Api\Management\Entity\App $decorated */
if ($decorated) {
$decorated = clone $decorated;
$decorated
->setCredentials();
}
parent::__construct($values, $entity_type, $decorated);
}
/**
* {@inheritdoc}
*/
public function deleteAttribute(string $name) : void {
$this->decorated
->deleteAttribute($name);
}
/**
* {@inheritdoc}
*/
public function getAppFamily() : string {
return $this->decorated
->getAppFamily();
}
/**
* {@inheritdoc}
*/
public function getAppId() : ?string {
return $this->decorated
->getAppId();
}
/**
* {@inheritdoc}
*/
public function getAttributeValue(string $attribute) : ?string {
return $this->decorated
->getAttributeValue($attribute);
}
/**
* {@inheritdoc}
*/
public function getAttributes() : AttributesProperty {
return $this->decorated
->getAttributes();
}
/**
* {@inheritdoc}
*/
public function getCallbackUrl() : ?string {
return $this->decorated
->getCallbackUrl();
}
/**
* {@inheritdoc}
*/
public function getCreatedAt() : ?\DateTimeImmutable {
return $this->decorated
->getCreatedAt();
}
/**
* {@inheritdoc}
*/
public function getCreatedBy() : ?string {
return method_exists($this->decorated, 'getCreatedBy') ? $this->decorated
->getCreatedBy() : '';
}
/**
* {@inheritdoc}
*/
public function getCredentials() : array {
// Return an empty array for a new app.
if (empty($this
->getAppId())) {
return [];
}
// Get app credentials from the shared app cache if available.
/** @var \Drupal\apigee_edge\Entity\Controller\Cache\AppCacheInterface $app_cache */
$app_cache = \Drupal::service('apigee_edge.controller.cache.apps');
$app = $app_cache
->getEntity($this
->getAppId());
if ($app === NULL) {
// App has not found in cache, we have to load it from Apigee Edge.
/** @var \Drupal\apigee_edge\Entity\Controller\AppControllerInterface $app_controller */
$app_controller = \Drupal::service('apigee_edge.controller.app');
try {
$app = $app_controller
->loadApp($this
->getAppId());
} catch (ApiException $e) {
// Just catch it and leave app to be NULL.
// It should never happen that we have an app id here that does not
// belong to an actually existing app in Apigee Edge.
}
}
return $app ? $app
->getCredentials() : [];
}
/**
* Make sure that credentials never gets cached.
*
* They should not be saved on this entity or on the decorated
* SDK entity object. This is just for extra alertness.
*
* @see \Drupal\apigee_edge\Entity\FieldableEdgeEntityBase::setPropertyValue()
*/
public function setCredentials() : void {
}
/**
* {@inheritdoc}
*/
public function getDescription() : ?string {
return $this->decorated
->getDescription();
}
/**
* {@inheritdoc}
*/
public function getDisplayName() : ?string {
return $this->decorated
->getDisplayName();
}
/**
* {@inheritdoc}
*/
public function getLastModifiedAt() : ?\DateTimeImmutable {
return $this->decorated
->getLastModifiedAt();
}
/**
* {@inheritdoc}
*/
public function getLastModifiedBy() : ?string {
return method_exists($this->decorated, 'getLastModifiedBy') ? $this->decorated
->getLastModifiedBy() : '';
}
/**
* {@inheritdoc}
*/
public function getName() : ?string {
return $this->decorated
->getName();
}
/**
* {@inheritdoc}
*/
public function getScopes() : array {
return $this->decorated
->getScopes();
}
/**
* {@inheritdoc}
*/
public function getStatus() : ?string {
return $this->decorated
->getStatus();
}
/**
* {@inheritdoc}
*/
public function hasAttribute(string $name) : bool {
return $this->decorated
->hasAttribute($name);
}
/**
* {@inheritdoc}
*/
public function setAppFamily(string $app_family) : void {
$this->decorated
->setAppFamily($app_family);
}
/**
* {@inheritdoc}
*/
public function setAttribute(string $name, string $value) : void {
$this->decorated
->setAttribute($name, $value);
}
/**
* {@inheritdoc}
*/
public function setAttributes(AttributesProperty $attributes) : void {
$this->decorated
->setAttributes($attributes);
}
/**
* {@inheritdoc}
*/
public function setCallbackUrl(string $callback_url) : void {
$this->decorated
->setCallbackUrl($callback_url);
}
/**
* {@inheritdoc}
*/
public function setDescription(string $description) : void {
$this->decorated
->setDescription($description);
}
/**
* {@inheritdoc}
*/
public function setDisplayName(string $display_name) : void {
$this->decorated
->setDisplayName($display_name);
}
/**
* {@inheritdoc}
*/
public function setScopes(string ...$scopes) : void {
$this->decorated
->setScopes(...$scopes);
}
/**
* {@inheritdoc}
*/
protected function drupalEntityId() : ?string {
return $this->decorated
->getAppId();
}
/**
* {@inheritdoc}
*/
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
/** @var \Drupal\Core\Field\BaseFieldDefinition[] $definitions */
$definitions = parent::baseFieldDefinitions($entity_type);
$definitions['name']
->setRequired(TRUE);
$definitions['displayName']
->setDisplayOptions('view', [
'label' => 'inline',
'weight' => 0,
])
->setDisplayOptions('form', [
'weight' => 0,
]);
$definitions['callbackUrl'] = BaseFieldDefinition::create('app_callback_url')
->setDisplayOptions('form', [
'weight' => 1,
])
->setDisplayOptions('view', [
'label' => 'inline',
'weight' => 2,
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE)
->setLabel(t('Callback URL'));
// Do not limit the length of the description because the API does not
// limit that either.
$definitions['description'] = static::getBaseFieldDefinition('description', 'string_long')
->setSetting('case_sensitive', TRUE)
->setDisplayOptions('form', [
'weight' => 2,
])
->setDisplayOptions('view', [
'label' => 'inline',
'weight' => 4,
]);
$definitions['status']
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'status_property',
'weight' => 1,
]);
$definitions['createdAt']
->setDisplayOptions('view', [
'type' => 'timestamp_ago',
'label' => 'inline',
'weight' => 3,
])
->setLabel(t('Created'));
$definitions['lastModifiedAt']
->setDisplayOptions('view', [
'type' => 'timestamp_ago',
'label' => 'inline',
'weight' => 5,
])
->setLabel(t('Last updated'));
// Hide readonly properties from Manage form display list.
$read_only_fields = [
'appId',
'appFamily',
'createdAt',
'lastModifiedAt',
'name',
'scopes',
'status',
];
foreach ($read_only_fields as $field) {
$definitions[$field]
->setDisplayConfigurable('form', FALSE);
}
return $definitions;
}
/**
* {@inheritdoc}
*/
protected static function propertyToBaseFieldTypeMap() : array {
return parent::propertyToBaseFieldBlackList() + [
// UUIDs (developerId, appId) managed on Apigee Edge so we do not
// want to expose them as UUID fields. Same applies for createdAt and
// lastModifiedAt. We do not want that Drupal apply default values
// on them if they are empty therefore their field type is a simple
// "timestamp" instead of "created" or "changed".
'createdAt' => 'timestamp',
'lastModifiedAt' => 'timestamp',
'scopes' => 'list_string',
'status' => 'string',
];
}
/**
* {@inheritdoc}
*/
protected static function propertyToBaseFieldBlackList() : array {
return array_merge(parent::propertyToBaseFieldBlackList(), [
// We expose credentials as a pseudo field.
'credentials',
]);
}
/**
* {@inheritdoc}
*/
public function get($field_name) {
$value = parent::get($field_name);
// Make sure that returned callback url field values are actually valid
// URLs. Apigee Edge allows to set anything as callbackUrl value but
// Drupal can only accept valid URIs.
if ($field_name === 'callbackUrl') {
if (!$value
->isEmpty()) {
foreach ($value
->getValue() as $id => $item) {
try {
Url::fromUri($item['value']);
} catch (\Exception $exception) {
$value
->removeItem($id);
}
}
}
}
return $value;
}
/**
* {@inheritdoc}
*/
public function set($field_name, $value, $notify = TRUE) {
// If the callback URL value is not a valid URL then save an empty string
// as the field value and set the callbackUrl property to the original
// value. (So we can display the original (invalid URL) on the edit form.)
// This trick is not necessary if the value's type is array because in this
// case the field value is set on the developer app edit form.
if ($field_name === 'callbackUrl' && !is_array($value)) {
try {
Url::fromUri($value);
} catch (\Exception $exception) {
/** @var \Drupal\apigee_edge\Entity\App $app */
$app = parent::set($field_name, '', $notify);
$app
->setCallbackUrl($value);
return $app;
}
}
return parent::set($field_name, $value, $notify);
}
/**
* {@inheritdoc}
*/
public function label() {
$label = parent::label();
// Return app name instead of app id if display name is missing.
if ($label === $this
->id()) {
$label = $this
->getName();
}
return $label;
}
/**
* {@inheritdoc}
*/
public function uuid() {
// Or $this->id().
return $this->decorated
->getAppId();
}
/**
* {@inheritdoc}
*/
public static function uniqueIdProperties() : array {
return array_merge(parent::uniqueIdProperties(), [
'appId',
]);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
App:: |
protected | property |
The decorated app entity from the SDK. Overrides AttributesAwareFieldableEdgeEntityBase:: |
2 |
App:: |
public static | function |
Provides base field definitions for an entity type. Overrides FieldableEdgeEntityBase:: |
2 |
App:: |
public | function | ||
App:: |
protected | function |
Return the entity id used in Drupal. Overrides EdgeEntityBase:: |
|
App:: |
public | function |
Gets a field item list. Overrides AttributesAwareFieldableEdgeEntityBase:: |
|
App:: |
public | function | ||
App:: |
public | function | ||
App:: |
public | function | ||
App:: |
public | function | ||
App:: |
public | function | ||
App:: |
public | function | ||
App:: |
public | function | ||
App:: |
public | function | ||
App:: |
public | function | ||
App:: |
public | function | ||
App:: |
public | function | ||
App:: |
public | function | ||
App:: |
public | function | ||
App:: |
public | function | ||
App:: |
public | function | ||
App:: |
public | function | ||
App:: |
public | function |
Gets the label of the entity. Overrides EdgeEntityBase:: |
|
App:: |
protected static | function |
Array of properties that should not be exposed as base fields by default. Overrides FieldableEdgeEntityBase:: |
|
App:: |
protected static | function |
Static mapping between entity properties and Drupal field types. Overrides FieldableEdgeEntityBase:: |
|
App:: |
public | function |
Sets a field value. Overrides FieldableEdgeEntityBase:: |
|
App:: |
public | function | ||
App:: |
public | function | ||
App:: |
public | function | ||
App:: |
public | function | ||
App:: |
public | function | Make sure that credentials never gets cached. | |
App:: |
public | function | ||
App:: |
public | function | ||
App:: |
public | function | ||
App:: |
public static | function |
Returns all unique ids how an entity can be referenced in Apigee Edge. Overrides EdgeEntityBase:: |
|
App:: |
public | function |
Gets the entity UUID (Universally Unique Identifier). Overrides EntityBase:: |
|
App:: |
public | function |
App constructor. Overrides AttributesAwareFieldableEdgeEntityBase:: |
2 |
AppInterface:: |
public | function | Returns the id of the app owner from the app entity. | 2 |
AppInterface:: |
public | function | Sets the app owner's property value on an app. | 2 |
AttributesAwareFieldableEdgeEntityBase:: |
protected | function | Returns the field-attribute converter service. | |
AttributesAwareFieldableEdgeEntityBase:: |
private | function | Sets attribute value from a field. | |
AttributesAwareFieldableEdgeEntityBase:: |
public | function |
Updates the property value on an entity by field name. Overrides FieldableEdgeEntityBase:: |
|
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:: |
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 |
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:: |
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 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:: |
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 |