Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 291765

Remove default/fallback entity form operation

$
0
0

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.


Viewing all articles
Browse latest Browse all 291765

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>