Skip to content

Conversation

@RaphTbm
Copy link

@RaphTbm RaphTbm commented Jun 30, 2025

Issue #1617

Description

Related to #1617 :: Twig - Flexibility to extend form select & submit, for extra classes + attributes

This a non breaking change proposal, so people would still have per project to extend the necessary and set those.
But on the long term, we should maybe force the attributes and attributes.class values/content into the final form element by default, so things can work properly by default for new projects without the need to extend those templates.

Copy link
Contributor

@22Alexandra 22Alexandra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the contribution, the changes will be done in #1630.

Comment on lines -9 to +11
{% set extraAttributes = [] %}
{% set extra_attributes = extra_attributes|default([]) %}
{% for name,value in attributes %}
{% set extraAttributes = extraAttributes|merge([{'name': name, 'value': value}]) %}
{% set extra_attributes = extra_attributes|merge([{'name': name, 'value': value}]) %}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes are not necessary because the way the template works now is passing the extraAttributes built from the existing attributes of the form element.

For example, these are the existing attributes of an element:
template preprocess
And these are the attributes rendered:
input--submit template

So, the desired extra attributes can safely be passed through the preprocess on the attributes array.

label: attributes.value,
variant: variant|default('primary'),
extra_attributes: extraAttributes
extra_classes: extra_classes|default(''),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, passing extra classes was missing. It's going to be fixed in #1630 and the extra classes can be passed through the preprocess on the class array of the attributes array.

Comment on lines +67 to +68
extra_classes: extra_classes_input|default(''),
extra_attributes: extra_attributes_input|default([]),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will be added in #1630.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants