function EntityDataDefinition::getPropertyDefinitions

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Entity/TypedData/EntityDataDefinition.php \Drupal\Core\Entity\TypedData\EntityDataDefinition::getPropertyDefinitions()
  2. 10 core/lib/Drupal/Core/Entity/TypedData/EntityDataDefinition.php \Drupal\Core\Entity\TypedData\EntityDataDefinition::getPropertyDefinitions()
  3. 11.x core/lib/Drupal/Core/Entity/TypedData/EntityDataDefinition.php \Drupal\Core\Entity\TypedData\EntityDataDefinition::getPropertyDefinitions()

Overrides ComplexDataDefinitionBase::getPropertyDefinitions

File

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

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::entityTypeManager()->getDefinition($entity_type_id)
                ->getClass();
            if (!in_array('Drupal\\Core\\Entity\\FieldableEntityInterface', class_implements($entity_type_class))) {
                $this->propertyDefinitions = [];
            }
            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::service('entity_field.manager')->getFieldDefinitions($entity_type_id, reset($bundles));
                }
                else {
                    $this->propertyDefinitions = \Drupal::service('entity_field.manager')->getBaseFieldDefinitions($entity_type_id);
                }
            }
        }
        else {
            // No entity type given.
            $this->propertyDefinitions = [];
        }
    }
    return $this->propertyDefinitions;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.