You are here

public function EdgeEntityType::getKeys in Apigee Edge 8

Gets an array of entity keys.

Return value

array An array describing how the Field API can extract certain information from objects of this entity type:

  • id: The name of the property that contains the primary ID of the entity. Every entity object passed to the Field API must have this property and its value must be numeric.
  • revision: (optional) The name of the property that contains the revision ID of the entity. The Field API assumes that all revision IDs are unique across all entities of a type. If this entry is omitted the entities of this type are not revisionable.
  • bundle: (optional) The name of the property that contains the bundle name for the entity. The bundle name defines which set of fields are attached to the entity (e.g. what nodes call "content type"). This entry can be omitted if this entity type exposes a single bundle (such that all entities have the same collection of fields). The name of this single bundle will be the same as the entity type.
  • label: (optional) The name of the property that contains the entity label. For example, if the entity's label is located in $entity->subject, then 'subject' should be specified here. If complex logic is required to build the label, \Drupal\Core\Entity\EntityInterface::label() should be used.
  • langcode: (optional) The name of the property that contains the language code. For instance, if the entity's language is located in $entity->langcode, then 'langcode' should be specified here.
  • uuid: (optional) The name of the property that contains the universally unique identifier of the entity, which is used to distinctly identify an entity across different systems.

Overrides EntityType::getKeys

File

src/Entity/EdgeEntityType.php, line 172

Class

EdgeEntityType
Provides an implementation of an Apigee Edge entity type and its metadata.

Namespace

Drupal\apigee_edge\Entity

Code

public function getKeys() {
  $keys = parent::getKeys();

  // If id definition is missing from the entity annotation try to set it up
  // automatically otherwise things gets broken, like entity reference fields.
  if (!isset($keys['id'])) {
    $rc = new \ReflectionClass($this
      ->getClass());

    // SDK entities can tell their primary id property.
    $method = 'idProperty';
    if ($rc
      ->hasMethod($method)) {
      $rm = $rc
        ->getMethod($method);
      $keys['id'] = $rm
        ->invoke(NULL, $method);
    }
  }
  return $keys;
}