Commit a3144f13 authored by alexpott's avatar alexpott

Issue #2936714 by gabesullice, Wim Leers, amateescu, Sam152, Berdir: Entity...

Issue #2936714 by gabesullice, Wim Leers, amateescu, Sam152, Berdir: Entity type definitions cannot be set as 'internal'
parent 9d81d2cd
......@@ -154,6 +154,13 @@ class EntityType extends PluginDefinition implements EntityTypeInterface {
*/
protected $data_table = NULL;
/**
* Indicates whether the entity data is internal.
*
* @var bool
*/
protected $internal = FALSE;
/**
* Indicates whether entities of this type have multilingual support.
*
......@@ -354,6 +361,13 @@ public function set($property, $value) {
return $this;
}
/**
* {@inheritdoc}
*/
public function isInternal() {
return $this->internal;
}
/**
* {@inheritdoc}
*/
......
......@@ -562,6 +562,24 @@ public function getBundleLabel();
*/
public function getBaseTable();
/**
* Indicates whether the entity data is internal.
*
* This can be used in a scenario when it is not desirable to expose data of
* this entity type to an external system.
*
* The implications of this method are left to the discretion of the caller.
* For example, a module providing an HTTP API may not expose entities of
* this type or a custom entity reference field settings form may deprioritize
* entities of this type in a select list.
*
* @return bool
* TRUE if the entity data is internal, FALSE otherwise.
*
* @see \Drupal\Core\TypedData\DataDefinitionInterface::isInternal()
*/
public function isInternal();
/**
* Indicates whether entities of this type have multilingual support.
*
......
......@@ -89,6 +89,7 @@ public function getDerivativeDefinitions($base_plugin_definition) {
$this->derivatives[$entity_type_id] = [
'label' => $entity_type->getLabel(),
'constraints' => $entity_type->getConstraints(),
'internal' => $entity_type->isInternal(),
] + $base_plugin_definition;
// Incorporate the bundles as entity:$entity_type:$bundle, if any.
......
......@@ -2,6 +2,8 @@
namespace Drupal\KernelTests\Core\Entity;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\TypedData\EntityDataDefinition;
use Drupal\Core\Entity\TypedData\EntityDataDefinitionInterface;
use Drupal\Core\Field\BaseFieldDefinition;
......@@ -138,4 +140,36 @@ public function testEntityReferences() {
$this->assertEqual(serialize($reference_definition2), serialize($reference_definition));
}
/**
* Tests that an entity annotation can mark the data definition as internal.
*
* @dataProvider entityDefinitionIsInternalProvider
*/
public function testEntityDefinitionIsInternal($internal, $expected) {
$entity_type_id = $this->randomMachineName();
$entity_type = $this->prophesize(EntityTypeInterface::class);
$entity_type->getLabel()->willReturn($this->randomString());
$entity_type->getConstraints()->willReturn([]);
$entity_type->isInternal()->willReturn($internal);
$entity_manager = $this->prophesize(EntityManagerInterface::class);
$entity_manager->getDefinitions()->willReturn([$entity_type_id => $entity_type->reveal()]);
$this->container->set('entity.manager', $entity_manager->reveal());
$entity_data_definition = EntityDataDefinition::create($entity_type_id);
$this->assertSame($expected, $entity_data_definition->isInternal());
}
/**
* Provides test cases for testEntityDefinitionIsInternal.
*/
public function entityDefinitionIsInternalProvider() {
return [
'internal' => [TRUE, TRUE],
'external' => [FALSE, FALSE],
'undefined' => [NULL, FALSE],
];
}
}
......@@ -127,6 +127,18 @@ public function providerTestGetKeys() {
];
}
/**
* Tests the isInternal() method.
*/
public function testIsInternal() {
$entity_type = $this->setUpEntityType(['internal' => TRUE]);
$this->assertTrue($entity_type->isInternal());
$entity_type = $this->setUpEntityType(['internal' => FALSE]);
$this->assertFalse($entity_type->isInternal());
$entity_type = $this->setUpEntityType([]);
$this->assertFalse($entity_type->isInternal());
}
/**
* Tests the isRevisionable() method.
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment