X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Flib%2FDrupal%2FCore%2FEntity%2FTypedData%2FEntityDataDefinition.php;fp=web%2Fcore%2Flib%2FDrupal%2FCore%2FEntity%2FTypedData%2FEntityDataDefinition.php;h=21c05d1e35d3f4097577eb48c182aba6b38a9ff0;hp=be6405af4abdf1a3ace551ce2ca0b08e2626390d;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/web/core/lib/Drupal/Core/Entity/TypedData/EntityDataDefinition.php b/web/core/lib/Drupal/Core/Entity/TypedData/EntityDataDefinition.php index be6405af4..21c05d1e3 100644 --- a/web/core/lib/Drupal/Core/Entity/TypedData/EntityDataDefinition.php +++ b/web/core/lib/Drupal/Core/Entity/TypedData/EntityDataDefinition.php @@ -18,13 +18,35 @@ class EntityDataDefinition extends ComplexDataDefinitionBase implements EntityDa * * @return static */ - public static function create($entity_type_id = NULL) { - $definition = new static([]); - // Set the passed entity type. + public static function create($entity_type_id = NULL, $bundle = NULL) { + // If the entity type is known, use the derived definition. if (isset($entity_type_id)) { + $data_type = "entity:{$entity_type_id}"; + + // If a bundle was given, use the bundle-specific definition. + if ($bundle) { + $data_type .= ":{$bundle}"; + } + + // It's possible that the given entity type ID or bundle wasn't discovered + // by the TypedData plugin manager and/or weren't created by the + // EntityDeriver. In that case, this is a new definition and we'll just + // create the definition from defaults by using an empty array. + $values = \Drupal::typedDataManager()->getDefinition($data_type, FALSE); + $definition = new static(is_array($values) ? $values : []); + + // Set the EntityType constraint using the given entity type ID. $definition->setEntityTypeId($entity_type_id); + + // If available, set the Bundle constraint. + if ($bundle) { + $definition->setBundles([$bundle]); + } + + return $definition; } - return $definition; + + return new static([]); } /** @@ -35,15 +57,10 @@ class EntityDataDefinition extends ComplexDataDefinitionBase implements EntityDa if ($parts[0] != 'entity') { throw new \InvalidArgumentException('Data type must be in the form of "entity:ENTITY_TYPE:BUNDLE."'); } - $definition = static::create(); - // Set the passed entity type and bundle. - if (isset($parts[1])) { - $definition->setEntityTypeId($parts[1]); - } - if (isset($parts[2])) { - $definition->setBundles([$parts[2]]); - } - return $definition; + return static::create( + isset($parts[1]) ? $parts[1] : NULL, + isset($parts[2]) ? $parts[2] : NULL + ); } /**