[6.x]: An image whose asset has no alt text is output with the asset's URL as alt
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 52/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- php
- Domain
- accessibility, backend
Research direction
Start by reading the asset reference construction in resources/assets/ckeditor/src/image/imageinsert/imageinsertui.js and the referenced resolution logic in Craft CMS's src/Element/Operations/ElementRefs.php. Trace how an empty alt value becomes a reference and check the relevant tests for reference resolution. Done means an image asset with no alternative text outputs alt="", while an asset with alternative text outputs that text.
Written by the indexing model from the issue text.
Description
Description
In 6.0.0-beta.2, an image inserted from an asset that has no alternative text is output with the asset's URL as its alt attribute.
The editor marks the alt text with an asset reference, also when the asset has none:
// resources/assets/ckeditor/src/image/imageinsert/imageinsertui.js
const alt = `${asset.alt ?? ''}#asset:${asset.id}${siteId ? `@${siteId}` : ''}:alt`;
On save, craftcms/html-field 4.0.0 turns that into a reference tag (HtmlField.php, "Find any alt text element refs and swap them with ref tags"): alt="{asset:18@2:alt}", with ||<text> when there was text.
When the tag is resolved, Craft returns the element's URL for an attribute that is not set:
// craftcms/cms, src/Element/Operations/ElementRefs.php (6.x-dev at 3c73751)
if (empty($attribute) || ! isset($element->$attribute)) {
return (string) $element->getUrl();
}
$asset->alt is null, so {asset:18@2:alt} resolves to the file's URL.
Steps to reproduce
- Craft 6.x-dev with
craftcms/ckeditor6.0.0-beta.2, a volume, and an image asset whose Alternative Text is empty. - A CKEditor field with the "Insert image" button on an entry type; create an entry and insert the asset from the toolbar. Save.
- Output the field in a template, and look at the stored value.
Expected behavior
alt="", or the alt text once the asset has one.
Actual behavior
Stored:
<figure class="image"><img src="{asset:18:url||http://127.0.0.1:8097/storage/spike/spike-photo.png}" alt="{asset:18@2:alt||http://127.0.0.1:8097/storage/spike/spike-photo.png}" width="320" height="200" /></figure>
Output: the image carries alt="http://127.0.0.1:8097/storage/spike/spike-photo.png".
A screen reader reads the URL aloud for every such image.
Versions
craftcms/ckeditor6.0.0-beta.2,craftcms/html-field4.0.0craftcms/cms6.x-devat 3c73751914389c1cde559d77a28ecf33265cb820- PHP 8.5.4, PostgreSQL 18, Ubuntu 26.04
- Dominant language
- PHP
- Stars
- 47
- Forks
- 35
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 25
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from craftcms/ckeditor
-
repo:ckeditor
Difficulty 1/5 Under an hour Newbie friendliness 78/100
craftcms/ckeditor#682 · 1 comment ·
Maintainers usually reply within 1 day
-
[6.x] Inline styles (alignment, font color, background color) are stripped on savePossibly taken @i-just claimed this today. Openrepo:ckeditor
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
craftcms/ckeditor#676 · 2 comments · 1 assignee ·
Maintainers usually reply within 1 day
-
bug repo:ckeditor
Difficulty 3/5 1-2 days Newbie friendliness 40/100
craftcms/ckeditor#665 · 2 comments · 1 assignee ·
Maintainers usually reply within 1 day
-
[6.x]: Esc in a fullscreen CKEditor field closes Preview instead of leaving fullscreenPossibly taken @i-just claimed this 15 days ago. Openbug repo:ckeditor
Difficulty 3/5 1-2 days Newbie friendliness 58/100
craftcms/ckeditor#651 · 3 comments · 1 assignee ·
Maintainers usually reply within 1 day
-
bug repo:ckeditor
Difficulty 3/5 1-2 days Newbie friendliness 54/100
craftcms/ckeditor#646 · 2 comments · 1 assignee ·
Maintainers usually reply within 1 day
All issues in craftcms/ckeditor
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Codeinwp/optimole-wp#1259 ·
Maintainers usually reply within 1 day
-
component/core domain/framework
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 1/5 Under an hour Newbie friendliness 75/100