I don't know of similar solutions. But the Webform module builds the controls from Yaml (the render array is created with Yaml::decode). It allows you to specify any attributes for an element and its wrapper in Yaml syntax.
I don't know why it might be unsafe. The attributes are stored in the configuration and are typed as a string. They are also passed to the element's #attributes and will be parsed/escaped on output like all other attributes.
- 🇩🇪Germany Anybody Porta Westfalica
Thanks @kay64, we have a similar request in https://www.drupal.org/project/menu_link_attributes/issues/3325692#comme... ✨ Add custom attributes support, e.g. 'download' Closed: cannot reproduce
One solution I thought about was a submodule to define the usable custom attributes in a setting and provide the value in each field. yaml is another option, which isn't bad, but not good UX for non-tech site builders.
So I'd prefer the submodule custom attribute definition thing. Seems to be a quite general requirements for such kind of modules?
- Status changed to Needs work
almost 2 years ago 5:36am 30 March 2023 - 🇩🇪Germany Anybody Porta Westfalica
Thinking about this for a while, I think the suggested MR by @kay64 is nice and smart. @kay64 could you please add an example as placeholder or in the description, for example for a "download" or a data attribute?
The module Layout Builder Component Attributes → has a similar functionality for date attributes, implemented in much the same way.
Added an example of modal window settings. There is also an example of usage in the textarea description.
- Status changed to Needs review
almost 2 years ago 9:17am 30 March 2023 - 🇩🇪Germany Anybody Porta Westfalica
Super cool, thank you @kay64! We should now check the security of this approach and best would be to have some automated tests, then this is ready to go from my side!
- last update
over 1 year ago 4 pass - @kksandr opened merge request.
I added tests, but I changed the way of testing, the presence of attributes is checked in the markup via DOMDocument.
- last update
over 1 year ago 4 pass - last update
over 1 year ago 4 pass - Status changed to Needs work
6 months ago 8:48am 4 September 2024 - 🇩🇪Germany Anybody Porta Westfalica
Thanks @kksandr! Looking good, but needs to be reworked now.