You are here

class DeveloperApp in Apigee Edge 8

Defines the Developer app entity class.

@\Drupal\apigee_edge\Annotation\EdgeEntityType( id = "developer_app", label =

Plugin annotation


@Translation("Developer App"),
  label_collection = @Translation("Developer Apps"),
  label_singular = @Translation("developer app"),
  label_plural = @Translation("developer apps"),
  label_count = @PluralTranslation(
    singular = "@count developer app",
    plural = "@count developer apps",
  ),
  config_with_labels = "apigee_edge.developer_app_settings",
  handlers = {
    "storage" = "Drupal\apigee_edge\Entity\Storage\DeveloperAppStorage",
    "access" = "Drupal\apigee_edge\Entity\EdgeEntityAccessControlHandler",
    "permission_provider" = "Drupal\apigee_edge\Entity\DeveloperAppPermissionProvider",
    "form" = {
      "default" = "Drupal\apigee_edge\Entity\Form\DeveloperAppCreateForm",
      "add" = "Drupal\apigee_edge\Entity\Form\DeveloperAppCreateForm",
      "add_for_developer" = "Drupal\apigee_edge\Entity\Form\DeveloperAppCreateFormForDeveloper",
      "edit" = "Drupal\apigee_edge\Entity\Form\DeveloperAppEditForm",
      "edit_for_developer" = "Drupal\apigee_edge\Entity\Form\DeveloperAppEditFormForDeveloper",
      "delete" = "Drupal\apigee_edge\Entity\Form\AppDeleteForm",
      "delete_for_developer" = "Drupal\apigee_edge\Entity\Form\DeveloperAppDeleteFormForDeveloper",
      "analytics" = "Drupal\apigee_edge\Form\DeveloperAppAnalyticsForm",
      "analytics_for_developer" = "Drupal\apigee_edge\Form\DeveloperAppAnalyticsFormForDeveloper",
      "add_api_key" = "Drupal\apigee_edge\Form\DeveloperAppApiKeyAddForm",
      "delete_api_key" = "Drupal\apigee_edge\Form\DeveloperAppApiKeyDeleteForm",
      "revoke_api_key" = "Drupal\apigee_edge\Form\DeveloperAppApiKeyRevokeForm",
    },
    "list_builder" = "Drupal\apigee_edge\Entity\ListBuilder\AppListBuilder",
    "view_builder" = "Drupal\apigee_edge\Entity\AppViewBuilder",
    "route_provider" = {
       "html" = "Drupal\apigee_edge\Entity\DeveloperAppRouteProvider",
    },
  },
  links = {
    "canonical" = "/developer-apps/{developer_app}",
    "collection" = "/developer-apps",
    "add-form" = "/developer-apps/add",
    "edit-form" = "/developer-apps/{developer_app}/edit",
    "delete-form" = "/developer-apps/{developer_app}/delete",
    "analytics" = "/developer-apps/{developer_app}/analytics",
    "canonical-by-developer" = "/user/{user}/apps/{app}",
    "collection-by-developer" = "/user/{user}/apps",
    "add-form-for-developer" = "/user/{user}/create-app",
    "edit-form-for-developer" = "/user/{user}/apps/{app}/edit",
    "delete-form-for-developer" = "/user/{user}/apps/{app}/delete",
    "analytics-for-developer" = "/user/{user}/apps/{app}/analytics",
    "api-keys" = "/user/{user}/apps/{app}/api-keys",
    "add-api-key-form" = "/user/{user}/apps/{app}/api-keys/add",
    "delete-api-key-form" = "/user/{user}/apps/{app}/api-keys/{consumer_key}/delete",
    "revoke-api-key-form" = "/user/{user}/apps/{app}/api-keys/{consumer_key}/revoke",
  },
  entity_keys = {
    "id" = "appId",
  },
  query_class = "Drupal\apigee_edge\Entity\Query\DeveloperAppQuery",
  admin_permission = "administer developer_app",
  field_ui_base_route = "apigee_edge.settings.developer_app",
)

Hierarchy

Expanded class hierarchy of DeveloperApp

16 files declare their use of DeveloperApp
ApigeeEdgeFunctionalTestTrait.php in tests/src/Traits/ApigeeEdgeFunctionalTestTrait.php
ApigeeMockApiClientHelperTrait.php in tests/modules/apigee_mock_api_client/tests/src/Traits/ApigeeMockApiClientHelperTrait.php
ApiProductAccessTest.php in tests/src/FunctionalJavascript/ApiProductAccessTest.php
AppListBuilderTest.php in tests/src/Kernel/Entity/ListBuilder/AppListBuilderTest.php
AppWarningsCheckerTest.php in tests/src/Kernel/Entity/AppWarningsCheckerTest.php

... See full list

File

src/Entity/DeveloperApp.php, line 94

Namespace

Drupal\apigee_edge\Entity
View source
class DeveloperApp extends App implements DeveloperAppInterface {

  /**
   * The cached Drupal UID.
   *
   * Use getOwnerId() to return the correct value.
   *
   * @var null|int
   */
  protected $drupalUserId;

  /**
   * The decorated developer app entity from the SDK.
   *
   * @var \Apigee\Edge\Api\Management\Entity\DeveloperApp
   */
  protected $decorated;

  /**
   * DeveloperApp 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 = NULL, ?EdgeEntityInterface $decorated = NULL) {

    // Little help to make it easier to initialize a new developer app object
    // with a property configured developerId which is required in app
    // creation.
    // @see DeveloperAppEntityControllerProxy::create()
    if (isset($values['drupalUserId'])) {
      $this
        ->setOwnerId($values['drupalUserId']);
    }

    /** @var \Apigee\Edge\Api\Management\Entity\DeveloperAppInterface $decorated */
    $entity_type = $entity_type ?? 'developer_app';
    parent::__construct($values, $entity_type, $decorated);
  }

  /**
   * We have to override this.
   *
   * This is how we could make it compatible with the SDK's
   * entity interface that has return type hint.
   */
  public function id() : ?string {
    return parent::id();
  }

  /**
   * {@inheritdoc}
   */
  public function getOwner() {
    $owner_id = $this
      ->getOwnerId();
    return $owner_id === NULL ? NULL : User::load($owner_id);
  }

  /**
   * {@inheritdoc}
   */
  public function setOwner(UserInterface $account) {
    $this
      ->setOwnerId($account
      ->id());
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function getOwnerId() {
    if ($this->drupalUserId === NULL) {
      if ($this
        ->getDeveloperId()) {
        $developer = Developer::load($this
          ->getDeveloperId());
        if ($developer) {

          /** @var \Drupal\user\UserInterface $account */
          $account = user_load_by_mail($developer
            ->getEmail());
          if ($account) {
            $this->drupalUserId = $account
              ->id();
          }
        }
      }
    }
    return $this->drupalUserId;
  }

  /**
   * Sets the entity owner's user ID.
   *
   * @param int $uid
   *   The owner user id.
   *
   * @return $this
   */
  public function setOwnerId($uid) {
    $this->drupalUserId = $uid;
    $user = User::load($uid);
    if ($user) {
      $developer = Developer::load($user
        ->getEmail());
      if ($developer) {
        $this->decorated
          ->setDeveloperId($developer
          ->uuid());
      }
      else {

        // Sanity check, probably someone called this method with invalid data.
        throw new InvalidArgumentException("Developer with {$user->getEmail()} email does not exist on Apigee Edge.");
      }
    }
    else {

      // Sanity check, probably someone called this method with invalid data.
      throw new InvalidArgumentException("User with {$uid} id does not exist.");
    }
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  protected static function decoratedClass() : string {
    return EdgeDeveloperApp::class;
  }

  /**
   * {@inheritdoc}
   */
  public static function idProperty() : string {
    return EdgeDeveloperApp::idProperty();
  }

  /**
   * {@inheritdoc}
   */
  public function getAppOwner() : ?string {
    return $this
      ->getDeveloperId();
  }

  /**
   * {@inheritdoc}
   */
  public function setAppOwner(string $owner) : void {
    $this->decorated
      ->setDeveloperId($owner);
  }

  /**
   * {@inheritdoc}
   */
  public function getDeveloperId() : ?string {
    return $this->decorated
      ->getDeveloperId();
  }

  /**
   * {@inheritdoc}
   */
  public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {

    /** @var \Drupal\Core\Field\BaseFieldDefinition[] $definitions */
    $definitions = parent::baseFieldDefinitions($entity_type);
    $developer_app_singular_label = \Drupal::entityTypeManager()
      ->getDefinition('developer_app')
      ->getSingularLabel();
    $developer_app_singular_label = mb_convert_case($developer_app_singular_label, MB_CASE_TITLE);
    $definitions['displayName']
      ->setLabel(t('@developer_app name', [
      '@developer_app' => $developer_app_singular_label,
    ]));
    $definitions['status']
      ->setLabel(t('@developer_app status', [
      '@developer_app' => $developer_app_singular_label,
    ]));
    $developer_app_settings = \Drupal::config('apigee_edge.developer_app_settings');
    foreach ((array) $developer_app_settings
      ->get('required_base_fields') as $required) {
      $definitions[$required]
        ->setRequired(TRUE);
    }

    // Hide readonly properties from Manage form display list.
    $definitions['developerId']
      ->setDisplayConfigurable('form', FALSE);
    return $definitions;
  }

  /**
   * {@inheritdoc}
   */
  protected function urlRouteParameters($rel) {
    $params = parent::urlRouteParameters($rel);
    $link_templates = $this
      ->linkTemplates();
    if (isset($link_templates[$rel])) {
      if (strpos($link_templates[$rel], '{user}') !== FALSE) {
        $params['user'] = $this
          ->getOwnerId();
      }
      if (strpos($link_templates[$rel], '{app}') !== FALSE) {
        $params['app'] = $this
          ->getName();
      }
      if (strpos($link_templates[$rel], '{developer_app}') === FALSE) {
        unset($params['developer_app']);
      }
    }
    return $params;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
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
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
DeveloperApp::$decorated protected property The decorated developer app entity from the SDK. Overrides App::$decorated
DeveloperApp::$drupalUserId protected property The cached Drupal UID.
DeveloperApp::baseFieldDefinitions public static function Provides base field definitions for an entity type. Overrides App::baseFieldDefinitions 1
DeveloperApp::decoratedClass protected static function The FQCN of the decorated class from the PHP API Client. Overrides EdgeEntityBase::decoratedClass
DeveloperApp::getAppOwner public function Returns the id of the app owner from the app entity. Overrides AppInterface::getAppOwner
DeveloperApp::getDeveloperId public function
DeveloperApp::getOwner public function Returns the entity owner's user entity. Overrides EntityOwnerInterface::getOwner
DeveloperApp::getOwnerId public function Returns the entity owner's user ID. Overrides EntityOwnerInterface::getOwnerId
DeveloperApp::id public function We have to override this. Overrides EdgeEntityBase::id
DeveloperApp::idProperty public static function
DeveloperApp::setAppOwner public function Sets the app owner's property value on an app. Overrides AppInterface::setAppOwner
DeveloperApp::setOwner public function Sets the entity owner's user entity. Overrides EntityOwnerInterface::setOwner
DeveloperApp::setOwnerId public function Sets the entity owner's user ID. Overrides EntityOwnerInterface::setOwnerId
DeveloperApp::urlRouteParameters protected function Gets an array of placeholders for this entity. Overrides EntityBase::urlRouteParameters
DeveloperApp::__construct public function DeveloperApp constructor. Overrides App::__construct
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::getTranslation public function
EdgeEntityBase::hasTranslation public function
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::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