[6.x]: An image whose asset has no alt text is output with the asset's URL as alt

Abierto
#678 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
52/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
php

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

repo:ckeditor
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
  1. Craft 6.x-dev with craftcms/ckeditor 6.0.0-beta.2, a volume, and an image asset whose Alternative Text is empty.
  2. A CKEditor field with the "Insert image" button on an entry type; create an entry and insert the asset from the toolbar. Save.
  3. 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/ckeditor 6.0.0-beta.2, craftcms/html-field 4.0.0
  • craftcms/cms 6.x-dev at 3c73751914389c1cde559d77a28ecf33265cb820
  • PHP 8.5.4, PostgreSQL 18, Ubuntu 26.04
Lenguaje dominante
PHP
Estrellas
47
Forks
35
Merge medio
1 d 2 h
PR fusionados (30 d)
25

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de craftcms/ckeditor

Todos los issues de craftcms/ckeditor

Issues similares

Más issues de PHP

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.