public function EntityDataDefinition::getPropertyDefinitions

public EntityDataDefinition::getPropertyDefinitions()

Gets an array of property definitions of contained properties.

Return value

\Drupal\Core\TypedData\DataDefinitionInterface[] An array of property definitions of contained properties, keyed by property name.

Overrides ComplexDataDefinitionBase::getPropertyDefinitions

File

core/lib/Drupal/Core/Entity/TypedData/EntityDataDefinition.php, line 52

Class

EntityDataDefinition
A typed data definition class for describing entities.

Namespace

Drupal\Core\Entity\TypedData

Code

public function getPropertyDefinitions() {
  if (!isset($this->propertyDefinitions)) {
    if ($entity_type_id = $this->getEntityTypeId()) {
      // Return an empty array for entities that are not content entities.
      $entity_type_class = \Drupal::entityManager()->getDefinition($entity_type_id)->getClass();
      if (!in_array('Drupal\Core\Entity\FieldableEntityInterface', class_implements($entity_type_class))) {
        $this->propertyDefinitions = array();
      }
      else {
        // @todo: Add support for handling multiple bundles.
        // See https://www.drupal.org/node/2169813.
        $bundles = $this->getBundles();
        if (is_array($bundles) && count($bundles) == 1) {
          $this->propertyDefinitions = \Drupal::entityManager()->getFieldDefinitions($entity_type_id, reset($bundles));
        }
        else {
          $this->propertyDefinitions = \Drupal::entityManager()->getBaseFieldDefinitions($entity_type_id);
        }
      }
    }
    else {
      // No entity type given.
      $this->propertyDefinitions = array();
    }
  }
  return $this->propertyDefinitions;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Entity!TypedData!EntityDataDefinition.php/function/EntityDataDefinition::getPropertyDefinitions/8.1.x