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.

CommentFileSizeAuthor
#2 insert-3000651-data_insert_attach.patch48.77 KBSnater
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Snater created an issue. See original summary.

Snater’s picture

Priority: Normal » Major
Status: Active » Needs review
Related issues: +#2981037: Update documentation
FileSize
48.77 KB

This 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:

{
  "id": {{ id }},
  "attributes": {
    "<attribute 1 name>": ["<primary attachment key>", "<fallback attachment key 1>", …],
    "<attribute 1 name>": ["<primary attachment key>", "<fallback attachment key 1>", …],
    …
  },
  "content": ["<primary attachment key>", "<fallback attachment key 1>", …]
}

Example from insert-image.html.twig:

data-insert-attach='{"id": "{{ id }}", "attributes": {"alt": ["alt", "description"], "title": ["title"]}}'

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.

  • Snater committed 8744618 on 8.x-2.x
    Issue #3000651: New text input synchronisation logic
    
Snater’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.