Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Text input (alt/title field) synchronisation is currently performed directly on the corresponding attributes, which may not reflect the placeholder placement in the template file. Either figure out a way to directly update the specific text or to replace the inserted template completely when altering text. If there is no other way, the synchronisation needs to be optional only.
Comment | File | Size | Author |
---|---|---|---|
#2 | insert-3000651-data_insert_attach.patch | 48.77 KB | Snater |
Comments
Comment #2
Snater CreditAttribution: Snater commentedThis is going to be a major breaking change.
The original placeholder mechanism inherited from D7 was very simple by intention. The advantage of __placeholders__ is that those are straight forward and very easy to use. The downside of that mechanism is that synchronising a field's input elements (e.g. the ALT text box) with the placeholder is next to impossible, because placeholders could potentially be placed anywhere inside or outside an attribute, DOM element or whatever, since there are no technical constraints. Yet, I regard synchronisation an important feature, so I would like to make the fundamentals for this functionality as robust as possible.
The attached change set (which is quite huge due to a lot of JS unit tests) drops the concept of placeholders. Instead, an attribute -
data-insert-attach
- is introduced that may be used to define "attachments" using a JSON structure:Example from insert-image.html.twig:
The pregenerated id (which currently is the file id, but I guess it is better to use the uuid for that purpose) is used to find the DOM node(s) to synchronise, which were placed in the textarea(s)/editor(s). "attributes" specifies which node attributes should be set to / synchronised with particular "attachment keys". These may be compared with the __placeholder__ names, which were mapped to CSS selectors, just like the attachment keys would be now. "content" specifies what the node's content should be replaced/synchronised with.
The concept of using JSON allows specifying fallbacks in a more logical structure, compared to the __[token]_or_filename__ placeholder. The concept of using an attribute inherits more constraints than using placeholders. However, these constrains make the concept more robust, particularly in terms on synchronisation. No regular expressions are required anymore, setting and synchronising attributes and content is done using DOM manipulation.
Comment #4
Snater CreditAttribution: Snater commented