You are here

abstract class App in Apigee Edge 8

Base class for App Drupal entities.

Hierarchy

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\Entity
View 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

Namesort descending Modifiers Type Description Overrides
App::$decorated protected property The decorated app entity from the SDK. Overrides AttributesAwareFieldableEdgeEntityBase::$decorated 2
App::baseFieldDefinitions public static function Provides base field definitions for an entity type. Overrides FieldableEdgeEntityBase::baseFieldDefinitions 2
App::deleteAttribute public function
App::drupalEntityId protected function Return the entity id used in Drupal. Overrides EdgeEntityBase::drupalEntityId
App::get public function Gets a field item list. Overrides AttributesAwareFieldableEdgeEntityBase::get
App::getAppFamily public function
App::getAppId public function
App::getAttributes public function
App::getAttributeValue public function
App::getCallbackUrl public function
App::getCreatedAt public function
App::getCreatedBy public function
App::getCredentials public function
App::getDescription public function
App::getDisplayName public function
App::getLastModifiedAt public function
App::getLastModifiedBy public function
App::getName public function
App::getScopes public function
App::getStatus public function
App::hasAttribute public function
App::label public function Gets the label of the entity. Overrides EdgeEntityBase::label
App::propertyToBaseFieldBlackList protected static function Array of properties that should not be exposed as base fields by default. Overrides FieldableEdgeEntityBase::propertyToBaseFieldBlackList
App::propertyToBaseFieldTypeMap protected static function Static mapping between entity properties and Drupal field types. Overrides FieldableEdgeEntityBase::propertyToBaseFieldTypeMap
App::set public function Sets a field value. Overrides FieldableEdgeEntityBase::set
App::setAppFamily public function
App::setAttribute public function
App::setAttributes public function
App::setCallbackUrl public function
App::setCredentials public function Make sure that credentials never gets cached.
App::setDescription public function
App::setDisplayName public function
App::setScopes public function
App::uniqueIdProperties public static function Returns all unique ids how an entity can be referenced in Apigee Edge. Overrides EdgeEntityBase::uniqueIdProperties
App::uuid public function Gets the entity UUID (Universally Unique Identifier). Overrides EntityBase::uuid
App::__construct public function App constructor. Overrides AttributesAwareFieldableEdgeEntityBase::__construct 2
AppInterface::getAppOwner public function Returns the id of the app owner from the app entity. 2
AppInterface::setAppOwner public function Sets the app owner's property value on an app. 2
AttributesAwareFieldableEdgeEntityBase::fieldAttributeConverter protected function Returns the field-attribute converter service.
AttributesAwareFieldableEdgeEntityBase::setAttributeValueFromField private function Sets attribute value from a field.
AttributesAwareFieldableEdgeEntityBase::setPropertyValue public function Updates the property value on an entity by field name. Overrides FieldableEdgeEntityBase::setPropertyValue
CacheableDependencyTrait::$cacheContexts protected property Cache contexts.
CacheableDependencyTrait::$cacheMaxAge protected property Cache max-age.
CacheableDependencyTrait::$cacheTags protected property Cache tags.
CacheableDependencyTrait::setCacheability protected function Sets cacheability; useful for value object constructors.
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function Aliased as: traitSleep 1
DependencySerializationTrait::__wakeup public function 2
EdgeEntityBase::createFrom public static function Creates a Drupal entity from an SDK Entity. Overrides EdgeEntityInterface::createFrom
EdgeEntityBase::decorated public function Returns the decorated SDK entity. Overrides EdgeEntityInterface::decorated 2
EdgeEntityBase::decoratedClass abstract protected static function The FQCN of the decorated class from the PHP API Client. 5
EdgeEntityBase::getTranslation public function
EdgeEntityBase::hasTranslation public function
EdgeEntityBase::id public function We have to override this to make it compatible with the SDK's entity interface that enforces the return type. Overrides EntityBase::id 5
EdgeEntityBase::isTranslatable public function
EdgeEntityBase::uniqueIds public function List of unique ids how an entity can be referenced in Apigee Edge. Overrides EdgeEntityInterface::uniqueIds
EntityBase::$enforceIsNew protected property Boolean indicating whether the entity should be forced to be new.
EntityBase::$entityTypeId protected property The entity type.
EntityBase::$typedData protected property A typed data object wrapping this entity.
EntityBase::access public function Checks data value access. Overrides AccessibleInterface::access 1
EntityBase::bundle public function Gets the bundle of the entity. Overrides EntityInterface::bundle 1
EntityBase::create public static function Constructs a new entity object, without permanently saving it. Overrides EntityInterface::create
EntityBase::createDuplicate public function Creates a duplicate of the entity. Overrides EntityInterface::createDuplicate 2
EntityBase::delete public function Deletes an entity permanently. Overrides EntityInterface::delete 2
EntityBase::enforceIsNew public function Enforces an entity to be new. Overrides EntityInterface::enforceIsNew
EntityBase::entityManager Deprecated protected function Gets the entity manager.
EntityBase::entityTypeBundleInfo protected function Gets the entity type bundle info service.
EntityBase::entityTypeManager protected function Gets the entity type manager.
EntityBase::getCacheContexts public function The cache contexts associated with this object. Overrides CacheableDependencyTrait::getCacheContexts
EntityBase::getCacheMaxAge public function The maximum age for which this object may be cached. Overrides CacheableDependencyTrait::getCacheMaxAge
EntityBase::getCacheTags public function The cache tags associated with this object. Overrides CacheableDependencyTrait::getCacheTags
EntityBase::getCacheTagsToInvalidate public function Returns the cache tags that should be used to invalidate caches. Overrides EntityInterface::getCacheTagsToInvalidate 2
EntityBase::getConfigDependencyKey public function Gets the key that is used to store configuration dependencies. Overrides EntityInterface::getConfigDependencyKey
EntityBase::getConfigDependencyName public function Gets the configuration dependency name. Overrides EntityInterface::getConfigDependencyName 1
EntityBase::getConfigTarget public function Gets the configuration target identifier for the entity. Overrides EntityInterface::getConfigTarget 1
EntityBase::getEntityType public function Gets the entity type definition. Overrides EntityInterface::getEntityType
EntityBase::getEntityTypeId public function Gets the ID of the type of the entity. Overrides EntityInterface::getEntityTypeId
EntityBase::getListCacheTagsToInvalidate protected function The list cache tags to invalidate for this entity.
EntityBase::getOriginalId public function Gets the original ID. Overrides EntityInterface::getOriginalId 1
EntityBase::getTypedData public function Gets a typed data object for this entity object. Overrides EntityInterface::getTypedData
EntityBase::hasLinkTemplate public function Indicates if a link template exists for a given key. Overrides EntityInterface::hasLinkTemplate
EntityBase::invalidateTagsOnDelete protected static function Invalidates an entity's cache tags upon delete. 1
EntityBase::invalidateTagsOnSave protected function Invalidates an entity's cache tags upon save. 1
EntityBase::isNew public function Determines whether the entity is new. Overrides EntityInterface::isNew 2
EntityBase::language public function Gets the language of the entity. Overrides EntityInterface::language 1
EntityBase::languageManager protected function Gets the language manager.
EntityBase::link public function Deprecated way of generating a link to the entity. See toLink(). Overrides EntityInterface::link 1
EntityBase::linkTemplates protected function Gets an array link templates. 1
EntityBase::load public static function Loads an entity. Overrides EntityInterface::load
EntityBase::loadMultiple public static function Loads one or more entities. Overrides EntityInterface::loadMultiple
EntityBase::postCreate public function Acts on a created entity before hooks are invoked. Overrides EntityInterface::postCreate 4
EntityBase::postDelete public static function Acts on deleted entities before the delete hook is invoked. Overrides EntityInterface::postDelete 16
EntityBase::postLoad public static function Acts on loaded entities. Overrides EntityInterface::postLoad 2
EntityBase::preCreate public static function Changes the values of an entity before it is created. Overrides EntityInterface::preCreate 5
EntityBase::preDelete public static function Acts on entities before they are deleted and before hooks are invoked. Overrides EntityInterface::preDelete 4
EntityBase::preSave public function Acts on an entity before the presave hook is invoked. Overrides EntityInterface::preSave 2
EntityBase::referencedEntities public function Gets a list of entities referenced by this entity. Overrides EntityInterface::referencedEntities 1
EntityBase::save public function Saves an entity permanently. Overrides EntityInterface::save 3
EntityBase::setOriginalId public function Sets the original ID. Overrides EntityInterface::setOriginalId 1
EntityBase::toLink public function Generates the HTML for a link to this entity. Overrides EntityInterface::toLink
EntityBase::toUrl public function Gets the URL object for the entity. Overrides EntityInterface::toUrl 2
EntityBase::uriRelationships public function Gets a list of URI relationships supported by this entity. Overrides EntityInterface::uriRelationships
EntityBase::url public function Gets the public URL for this entity. Overrides EntityInterface::url 2
EntityBase::urlInfo public function Gets the URL object for the entity. Overrides EntityInterface::urlInfo 1
EntityBase::urlRouteParameters protected function Gets an array of placeholders for this entity. 2
EntityBase::uuidGenerator protected function Gets the UUID generator.
FieldableEdgeEntityBase::$fieldDefinitions protected property Local cache for field definitions.
FieldableEdgeEntityBase::$fields protected property Local cache for for fields.
FieldableEdgeEntityBase::$validated protected property Whether entity validation was performed.
FieldableEdgeEntityBase::$validationRequired protected property Whether entity validation is required before saving the entity.
FieldableEdgeEntityBase::bundleFieldDefinitions public static function Provides field definitions for a specific bundle. Overrides FieldableEntityInterface::bundleFieldDefinitions
FieldableEdgeEntityBase::convertFieldValueToPropertyValue protected function Converts a field value to a property value.
FieldableEdgeEntityBase::exposePropertyAsBaseField private static function Returns whether an entity property is blacklisted to be exposed as field.
FieldableEdgeEntityBase::getBaseFieldDefinition protected static function Attempts to create a base field definition from a type.
FieldableEdgeEntityBase::getFieldDefinition public function Gets the definition of a contained field. Overrides FieldableEntityInterface::getFieldDefinition
FieldableEdgeEntityBase::getFieldDefinitions public function Gets an array of field definitions of all contained fields. Overrides FieldableEntityInterface::getFieldDefinitions
FieldableEdgeEntityBase::getFields public function Gets an array of all field item lists. Overrides FieldableEntityInterface::getFields
FieldableEdgeEntityBase::getFieldValue protected function Returns the field value from the current object.
FieldableEdgeEntityBase::getIterator public function
FieldableEdgeEntityBase::getProperties protected static function Parses the properties and its types from the parent class.
FieldableEdgeEntityBase::getTranslatableFields public function Gets an array of field item lists for translatable fields. Overrides FieldableEntityInterface::getTranslatableFields
FieldableEdgeEntityBase::hasField public function Determines whether the entity has a field with the given name. Overrides FieldableEntityInterface::hasField
FieldableEdgeEntityBase::isValidationRequired public function Checks whether entity validation is required before saving the entity. Overrides FieldableEntityInterface::isValidationRequired
FieldableEdgeEntityBase::onChange public function Reacts to changes to a field. Overrides FieldableEntityInterface::onChange
FieldableEdgeEntityBase::postSave public function Acts on a saved entity before the insert or update hook is invoked. Overrides EntityBase::postSave
FieldableEdgeEntityBase::propertyFieldType private static function Returns the type of the field that should represent an entity property.
FieldableEdgeEntityBase::setValidationRequired public function Sets whether entity validation is required before saving the entity. Overrides FieldableEntityInterface::setValidationRequired
FieldableEdgeEntityBase::toArray public function Gets an array of all property values. Overrides EntityBase::toArray
FieldableEdgeEntityBase::validate public function Validates the currently set values. Overrides FieldableEntityInterface::validate
FieldableEdgeEntityBase::__sleep public function Overrides EntityBase::__sleep
RefinableCacheableDependencyTrait::addCacheableDependency public function 1
RefinableCacheableDependencyTrait::addCacheContexts public function
RefinableCacheableDependencyTrait::addCacheTags public function
RefinableCacheableDependencyTrait::mergeCacheMaxAge public function
RevisioningWorkaroundTrait::getLoadedRevisionId public function
RevisioningWorkaroundTrait::getRevisionId public function
RevisioningWorkaroundTrait::isDefaultRevision public function
RevisioningWorkaroundTrait::isLatestRevision public function
RevisioningWorkaroundTrait::isNewRevision public function
RevisioningWorkaroundTrait::preSaveRevision public function
RevisioningWorkaroundTrait::setNewRevision public function
RevisioningWorkaroundTrait::updateLoadedRevisionId public function
RevisioningWorkaroundTrait::wasDefaultRevision public function