Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Form::getAttributesHTML() incorrectly escaped in templates #10386

Closed
kinglozzer opened this issue Jul 4, 2022 · 1 comment
Closed

Form::getAttributesHTML() incorrectly escaped in templates #10386

kinglozzer opened this issue Jul 4, 2022 · 1 comment

Comments

@kinglozzer
Copy link
Member

kinglozzer commented Jul 4, 2022

Affected Version

4.x

Description

Forms and form fields have two methods of outputting HTML attributes, $AttributesHTML and $getAttributesHTML('class'), where the 2nd example will output all attributes except the class attribute.

IIRC the reason behind this is that $AttributesHTML will call getAttributesHTML() but won’t pass through any arguments (this was an opinionated design decision in the template engine because getters traditionally shouldn’t have arguments), so it’s necessary to include the get prefix if you want arguments included.

Form is missing 'getAttributesHTML' => 'HTMLFragment' from its casting array. The AttributesHTML trait actually mentions this requirement in its documentation:

* When applying this trait to a class, you also need to add the following casting configuration.
* ```
* private static $casting = [
* 'AttributesHTML' => 'HTMLFragment',
* 'getAttributesHTML' => 'HTMLFragment',
* ];
* ```

With this casting missing, using $getAttributesHTML('class') on a Form instance in templates results in escaping on quotes for the attribute values

@michalkleiner
Copy link
Contributor

Closing as linked PR merged.

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

No branches or pull requests

2 participants