enforce entity form operation keys to be machine names

Created on 18 October 2016, over 8 years ago
Updated 27 May 2025, 4 days ago

The form operations defined in an entity's annotation can be given arbitrary keys, thus:

 *   handlers = {
 *     "form" = {
 *       "default" = "Drupal\myentity\Form\MyEntityForm",
 *       "add" = "Drupal\myentity\Form\MyEntityForm",
 *       "foo-bar" = "Drupal\myentity\Form\MyEntityForm",

The system allows non-machine names here, such as 'foo-bar'.

This causes several problems.

The form operation name becomes part of the form ID, which is 'ENTITYTYPE-OPERATIONNAME-form', thus myentity_foo-bar_form. This won't work with hook_form_FORM_ID_alter(), as it won't make a PHP function name.

Also, form operation names correspond to entity form view modes, which are config entities and so have machine name IDs. That means that the 'foo-bar' operation can't have a matching view mode created for it.

Therefore, the entity system should enforce form operation names to be proper machine names.

πŸ› Bug report
Status

Active

Version

11.0 πŸ”₯

Component

entity system

Created by

πŸ‡¬πŸ‡§United Kingdom joachim

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Came up as a daily BSI target

    This still appears to be the case, example

    * "delete-multiple-confirm" = "Drupal\Core\Entity\Form\DeleteMultipleForm"

    But is it still a problem?

Production build 0.71.5 2024