diff --git a/core/lib/Drupal/Core/Entity/EntityType.php b/core/lib/Drupal/Core/Entity/EntityType.php index 85794d3..e7ef60b 100644 --- a/core/lib/Drupal/Core/Entity/EntityType.php +++ b/core/lib/Drupal/Core/Entity/EntityType.php @@ -381,6 +381,13 @@ public function setForm($operation, $class) { /** * {@inheritdoc} */ + public function hasForms() { + return !empty($this->controllers['form']); + } + + /** + * {@inheritdoc} + */ public function getList() { return $this->getController('list'); } diff --git a/core/lib/Drupal/Core/Entity/EntityTypeInterface.php b/core/lib/Drupal/Core/Entity/EntityTypeInterface.php index 6f185e8..44103f3 100644 --- a/core/lib/Drupal/Core/Entity/EntityTypeInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityTypeInterface.php @@ -243,6 +243,14 @@ public function getForm($operation); public function setForm($operation, $class); /** + * Indicates if this entity type has any forms. + * + * @return bool + * TRUE if there are any forms for this entity type, FALSE otherwise. + */ + public function hasForms(); + + /** * Returns the list class. * * @return string diff --git a/core/modules/entity/lib/Drupal/entity/Controller/EntityDisplayModeController.php b/core/modules/entity/lib/Drupal/entity/Controller/EntityDisplayModeController.php index e0f1d0f..4160f99 100644 --- a/core/modules/entity/lib/Drupal/entity/Controller/EntityDisplayModeController.php +++ b/core/modules/entity/lib/Drupal/entity/Controller/EntityDisplayModeController.php @@ -74,7 +74,7 @@ public function viewModeTypeSelection() { public function formModeTypeSelection() { $entity_types = array(); foreach ($this->entityManager->getDefinitions() as $entity_type => $entity_info) { - if ($entity_info->isFieldable() && $entity_info->hasController('form')) { + if ($entity_info->isFieldable() && $entity_info->hasForms()) { $entity_types[$entity_type] = array( 'title' => $entity_info->getLabel(), 'href' => 'admin/structure/display-modes/form/add/' . $entity_type, diff --git a/core/modules/entity/lib/Drupal/entity/EntityFormModeListController.php b/core/modules/entity/lib/Drupal/entity/EntityFormModeListController.php index 0ae68f1..9f42ff2 100644 --- a/core/modules/entity/lib/Drupal/entity/EntityFormModeListController.php +++ b/core/modules/entity/lib/Drupal/entity/EntityFormModeListController.php @@ -19,11 +19,10 @@ class EntityFormModeListController extends EntityDisplayModeListController { * The entity type of the entity that needs to be validated. * * @return bool - * TRUE if the entity has the correct controller, FALSE if the entity - * doesn't has the correct controller. + * TRUE if the entity has any form controllers, FALSE otherwise. */ protected function isValidEntity($entity_type) { - return $this->entityInfoComplete[$entity_type]->hasController('form'); + return $this->entityInfoComplete[$entity_type]->hasForms(); } } diff --git a/core/modules/entity/lib/Drupal/entity/Form/EntityFormModeAddForm.php b/core/modules/entity/lib/Drupal/entity/Form/EntityFormModeAddForm.php index ce27c0f..ffacd4f 100644 --- a/core/modules/entity/lib/Drupal/entity/Form/EntityFormModeAddForm.php +++ b/core/modules/entity/lib/Drupal/entity/Form/EntityFormModeAddForm.php @@ -19,7 +19,7 @@ class EntityFormModeAddForm extends EntityDisplayModeAddForm { */ protected function prepareEntity() { $definition = $this->entityManager->getDefinition($this->entityType); - if (!$definition->isFieldable() || !$definition->hasController('form')) { + if (!$definition->isFieldable() || !$definition->hasForms()) { throw new NotFoundHttpException(); } diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php index 19614ef..5ed6562 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php @@ -158,6 +158,26 @@ public function testGetForm() { } /** + * Tests the hasForms() method. + */ + public function testHasForms() { + $controller = 'Drupal\Tests\Core\Entity\TestEntityController'; + $operation = 'default'; + $entity_type1 = $this->setUpEntityType(array( + 'controllers' => array( + 'form' => array( + $operation => $controller, + ), + ), + )); + $entity_type2 = $this->setUpEntityType(array( + 'controllers' => array(), + )); + $this->assertTrue($entity_type1->hasForms()); + $this->assertFalse($entity_type2->hasForms()); + } + + /** * Tests the getViewBuilder() method. */ public function testGetViewBuilder() {