Use a simplified form ID if the form ID is too specific - ends with Entities IDs

Created on 19 February 2024, 11 months ago
Updated 1 September 2024, 5 months ago

Problem/Motivation

I tried to use this module within Drupal Commerce - Add To Cart Form
But as this form could be present in multiple places in the page, the form ID has to be specific ... like "purchased entity type + purchased entity id" are added to the form ID.
And it "would be nice" to have a way to easy customise "Add to Cart" buttons for example - like add an icon or something.

Similar approach exists in StateTransitionForm - state_machine module.
There could be other usages when an entity type and entity id is needed to make the form id "unique".

Steps to reproduce

Just use the module on Drupal commerce in a "catalog" with Add to cart for products and/or product page
and check the theme suggestions in debug mode.
There is a suggestion too specific to be used or too generic.
Example

<!-- FILE NAME SUGGESTIONS:
   * input--submit--commerce-order-item-add-to-cart-form-commerce-product-3416--op.html.twig
   * input--submit--commerce-order-item-add-to-cart-form-commerce-product-3416.html.twig
   * input--submit.html.twig
   x input.html.twig
-->

Proposed resolution

To use the form theme suggestions instead, in those cases.
Example

<!-- FILE NAME SUGGESTIONS:
   * input--submit--commerce-order-item-add-to-cart-form--op.html.twig
   x input--submit--commerce-order-item-add-to-cart-form.html.twig
   * input--submit.html.twig
   x input--submit--commerce-order-item-add-to-cart-form.html.twig
   * input.html.twig
-->
✨ Feature request
Status

Fixed

Version

4.0

Component

Code

Created by

πŸ‡·πŸ‡΄Romania vasike Ramnicu Valcea

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024