Skip to content
Snippets Groups Projects
Commit 2867e69a authored by Angie Byron's avatar Angie Byron
Browse files

Issue #2228721 by amateescu, drunken monkey: TypedData doesn't support config...

Issue #2228721 by amateescu, drunken monkey: TypedData doesn't support config entity types; flag errors if you try.
parent ed38d9eb
No related branches found
No related tags found
No related merge requests found
......@@ -341,12 +341,18 @@ public function getBaseFieldDefinitions($entity_type_id) {
* An array of field definitions, keyed by field name.
*
* @throws \LogicException
* Thrown if one of the entity keys is flagged as translatable.
* Thrown if a config entity type is given or if one of the entity keys is
* flagged as translatable.
*/
protected function buildBaseFieldDefinitions($entity_type_id) {
$entity_type = $this->getDefinition($entity_type_id);
$class = $entity_type->getClass();
// Fail with an exception for config entity types.
if (!$entity_type->isSubclassOf('\Drupal\Core\Entity\ContentEntityInterface')) {
throw new \LogicException(String::format('Getting the base fields is not supported for entity type @type.', array('@type' => $entity_type->getLabel())));
}
// Retrieve base field definitions and assign them the entity type provider.
$base_field_definitions = $class::baseFieldDefinitions($entity_type);
$provider = $entity_type->getProvider();
......
......@@ -57,14 +57,21 @@ public static function createFromDataType($data_type) {
public function getPropertyDefinitions() {
if (!isset($this->propertyDefinitions)) {
if ($entity_type_id = $this->getEntityTypeId()) {
// @todo: Add support for handling multiple bundles.
// See https://drupal.org/node/2169813.
$bundles = $this->getBundles();
if (is_array($bundles) && count($bundles) == 1) {
$this->propertyDefinitions = \Drupal::entityManager()->getFieldDefinitions($entity_type_id, reset($bundles));
// Return an empty array for entity types that don't support typed data.
$entity_type_class = \Drupal::entityManager()->getDefinition($entity_type_id)->getClass();
if (!in_array('Drupal\Core\TypedData\TypedDataInterface', class_implements($entity_type_class))) {
$this->propertyDefinitions = array();
}
else {
$this->propertyDefinitions = \Drupal::entityManager()->getBaseFieldDefinitions($entity_type_id);
// @todo: Add support for handling multiple bundles.
// See https://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 {
......
......@@ -114,6 +114,10 @@ public function testEntities() {
// entity data types variants.
$this->assertEqual($this->typedDataManager->createDataDefinition('entity'), EntityDataDefinition::create());
$this->assertEqual($this->typedDataManager->createDataDefinition('entity:node'), EntityDataDefinition::create('node'));
// Config entities don't support typed data.
$entity_definition = EntityDataDefinition::create('node_type');
$this->assertEqual(array(), $entity_definition->getPropertyDefinitions());
}
/**
......
......@@ -695,6 +695,10 @@ protected function setUpEntityWithFieldDefinition($custom_invoke_all = FALSE, $f
$entity_type->expects($this->any())
->method('getKeys')
->will($this->returnValue(array()));
$entity_type->expects($this->any())
->method('isSubclassOf')
->with($this->equalTo('\Drupal\Core\Entity\ContentEntityInterface'))
->will($this->returnValue(TRUE));
$field_definition = $this->getMockBuilder('Drupal\Core\Field\FieldDefinition')
->disableOriginalConstructor()
->getMock();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment