Problem/Motivation
When Entity Form Controllers were introduced, it came with the concept of a "default" form, where you could just call entity_get_form($entity)
, with no specified operation.
This has led to reuse of entity forms for both add and edit, with odd and inconsistent hacks spread through them (like $entity->isNew()
) to differentiate between them.
Proposed resolution
Encourage use of separate form controllers that share a base class.
In the meantime, just duplicate the form declaration in the annotation to reuse the single class for each operation:
diff --git a/core/modules/user/lib/Drupal/user/Plugin/Core/Entity/Role.php b/core/modules/user/lib/Drupal/user/Plugin/Core/Entity/Role.php
index 5a288c8..1bfcd02 100644
--- a/core/modules/user/lib/Drupal/user/Plugin/Core/Entity/Role.php
+++ b/core/modules/user/lib/Drupal/user/Plugin/Core/Entity/Role.php
@@ -24,7 +24,8 @@
* "access" = "Drupal\user\RoleAccessController",
* "list" = "Drupal\user\RoleListController",
* "form" = {
- * "default" = "Drupal\user\RoleFormController"
+ * "add" = "Drupal\user\RoleFormController",
+ * "edit" = "Drupal\user\RoleFormController"
* }
* },
* config_prefix = "user.role",
Remaining tasks
N/A
User interface changes
N/A
API changes
$operation is no longer optional when calling entity_get_form() et al.