diff -u b/core/lib/Drupal/Core/Entity/Entity.php b/core/lib/Drupal/Core/Entity/Entity.php --- b/core/lib/Drupal/Core/Entity/Entity.php +++ b/core/lib/Drupal/Core/Entity/Entity.php @@ -7,9 +7,10 @@ namespace Drupal\Core\Entity; -use Drupal\Component\Utility\Unicode; use Drupal\Core\DependencyInjection\DependencySerialization; use Drupal\Component\Utility\String; +use Drupal\Component\Utility\Unicode; +use Drupal\Core\Config\Entity\Exception\ConfigEntityIdLengthException; use Drupal\Core\Entity\Exception\UndefinedLinkTemplateException; use Drupal\Core\Language\Language; use Drupal\Core\Session\AccountInterface; @@ -339,10 +340,10 @@ if ($this->getEntityType()->getBundleOf()) { // Throw an exception if the bundle ID is longer than 32 characters. if (Unicode::strlen($this->id()) > EntityTypeInterface::BUNDLE_MAX_LENGTH) { - throw new EntityMalformedException(String::format( - 'Attempt to create a bundle with an ID longer than @max characters: %ID.', array( + throw new ConfigEntityIdLengthException(String::format( + 'Attempt to create a bundle with an ID longer than @max characters: @id.', array( '@max' => EntityTypeInterface::BUNDLE_MAX_LENGTH, - '%ID' => $this->id(), + '@id' => $this->id(), ) )); } diff -u b/core/lib/Drupal/Core/Entity/EntityType.php b/core/lib/Drupal/Core/Entity/EntityType.php --- b/core/lib/Drupal/Core/Entity/EntityType.php +++ b/core/lib/Drupal/Core/Entity/EntityType.php @@ -9,6 +9,7 @@ use Drupal\Component\Utility\String; use Drupal\Component\Utility\Unicode; +use Drupal\Core\Entity\Exception\EntityTypeIdLengthException; /** * Provides an implementation of an entity type and its metadata. @@ -183,16 +184,17 @@ * * @param array $definition * An array of values from the annotation. - * @throws EntityMalformedException - * When attempting to instantiate an entity type with too long ID. + * + * @throws \Drupal\Core\Entity\Exception\EntityTypeIdLengthException + * Thrown when attempting to instantiate an entity type with too long ID. */ public function __construct($definition) { // Throw an exception if the entity type ID is longer than 32 characters. - if (Unicode::strlen($definition['id'] > static::ID_MAX_LENGTH)) { - throw new EntityMalformedException(String::format( - 'Attempt to create an entity type with an ID longer than @max characters: %ID.', array( + if (Unicode::strlen($definition['id']) > static::ID_MAX_LENGTH) { + throw new EntityTypeIdLengthException(String::format( + 'Attempt to create an entity type with an ID longer than @max characters: @id.', array( '@max' => static::ID_MAX_LENGTH, - '%ID' => $definition['id'], + '@id' => $definition['id'], ) )); } diff -u b/core/lib/Drupal/Core/Entity/EntityTypeInterface.php b/core/lib/Drupal/Core/Entity/EntityTypeInterface.php --- b/core/lib/Drupal/Core/Entity/EntityTypeInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityTypeInterface.php @@ -18,9 +18,13 @@ interface EntityTypeInterface { /** - * The maximum length of ID and bundle name, in characters. + * The maximum length of ID, in characters. */ const ID_MAX_LENGTH = 32; + + /** + * The maximum length of bundle name, in characters. + */ const BUNDLE_MAX_LENGTH = 32; /** diff -u b/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php --- b/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php @@ -199,11 +199,10 @@ public function testIdExceedsMaxLength() { $id = $this->randomName(33); $message = 'Attempt to create an entity type with an ID longer than 32 characters: ' . $id; - $this->setExpectedException('Drupal\Core\Entity\EntityMalformedException', $message); + $this->setExpectedException('Drupal\Core\Entity\Exception\EntityTypeIdLengthException', $message); $this->setUpEntityType(array('id' => $id)); } - /** * @covers ::id */ only in patch2: unchanged: --- /dev/null +++ b/core/lib/Drupal/Core/Config/Entity/Exception/ConfigEntityIdLengthException.php @@ -0,0 +1,15 @@ + 'example_config_entity_type', + ); + } + return new ConfigEntityType($definition); + } /** * Tests that we get an exception when the length of the config prefix that is @@ -39,7 +55,7 @@ public static function getInfo() { * @covers ::getConfigPrefix() */ public function testConfigPrefixLengthExceeds($entity_data, $exception, $message) { - $config_entity = new ConfigEntityType($entity_data); + $config_entity = $this->setUpConfigEntityType($entity_data); $this->setExpectedException($exception, $message); $this->assertEmpty($config_entity->getConfigPrefix()); } @@ -95,7 +111,7 @@ public function providerPrefixLengthExceeds() { * @covers ::getConfigPrefix() */ public function testConfigPrefixLengthValid($entity_data) { - $config_entity = new ConfigEntityType($entity_data); + $config_entity = $this->setUpConfigEntityType($entity_data); if (isset($entity_data['config_prefix'])) { $expected_prefix = $entity_data['provider'] . '.' . $entity_data['config_prefix']; } else {