Skip to content

[chore] Add automatic alt text for images in CKEditor fields - #301

Merged
superextinct merged 1 commit into
mainfrom
chore/ckeditor-image-alt
Mar 3, 2026
Merged

[chore] Add automatic alt text for images in CKEditor fields#301
superextinct merged 1 commit into
mainfrom
chore/ckeditor-image-alt

Conversation

@superextinct

Copy link
Copy Markdown
Collaborator

This PR adds the retconAutoAlt filter when rendering CKEditor fields, which outputs each asset's alt text on tags.

Note: This filter must be called before any other filters that would serialize the field data. Serialization parses reference tags, preventing Retcon from locating the original asset to retrieve its alt text.

@superextinct
superextinct requested a review from harryfk March 3, 2026 11:00
@harryfk

harryfk commented Mar 3, 2026

Copy link
Copy Markdown
Collaborator

Does this do something for us, after all?

@superextinct

Copy link
Copy Markdown
Collaborator Author

Yes! It wasn't working previously in this order:

text                  // <img src="{asset:31382:url||/uploads/Prototypefund-7720.jpg}" />
  |replace({
    '/<div class="col-xs-24">/': "",
    "/<\/div>$/": ""
  })                  // <img src="/uploads/Prototypefund-7720.jpg" />
  |retconAutoAlt      // no bueno, Retcon can't resolve asset from src

It works correctly when retconAutoAlt is called before the CKeditor field data is serialized:

text                  // <img src="{asset:31382:url||/uploads/Prototypefund-7720.jpg}" />
  |retconAutoAlt      // craft\elements\Asset
  |replace({
    '/<div class="col-xs-24">/': "",
    "/<\/div>$/": ""
  })                

@superextinct superextinct changed the title Add automatic alt text for images in CKEditor fields [chore] Add automatic alt text for images in CKEditor fields Mar 3, 2026
@harryfk

harryfk commented Mar 3, 2026

Copy link
Copy Markdown
Collaborator

Oh, cool, good to know! That makes a lot of sense, actually.

@superextinct
superextinct merged commit 0bd3b78 into main Mar 3, 2026
1 check passed
@superextinct
superextinct deleted the chore/ckeditor-image-alt branch March 3, 2026 16:27
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