Problem/Motivation

When configuring an SVG Image Field with the "Alt field" enabled and "Alt field required" setting checked, the validation does not work correctly. Users can upload an SVG file, leave the alternative text field empty, and save the form without any validation error.

Steps to reproduce

  1. Create or edit a content type/block type with an SVG Image Field
  2. In the field settings, enable "Alt field" and check "Alt field required"
  3. Save the field configuration
  4. Go to create/edit content using this field
  5. Upload an SVG file
  6. Leave the "Alternative text" field empty
  7. Click Save

Expected behavior:
A validation error should appear: "Alternative text field is required." and the form should not submit.

Actual behavior:
The form saves successfully without any validation error, allowing content with missing alt text to be created.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

n.ghunaim created an issue. See original summary.

n.ghunaim’s picture

Status: Active » Needs review
jwilson3’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Please add a test that demonstrates the bug and validates the fix. With GitLab CI we now have a way to run only tests, without the fix.

a sahil madan goud made their first commit to this issue’s fork.

a sahil madan goud’s picture

I’ve added a functional test covering the required alt text validation for SVG uploads.
Please let me know if any changes are needed.

jwilson3’s picture

Thanks for adding the tests! It needs a little more work though.

  1. There are PhpCS errors on the new test file.
  2. There is 1 phpunit test failure:
    SvgImageFieldAltRequiredTest::testAltTextRequiredForSvgUpload:
    Form field with id|name|label|value "field_svg[0][upload]" not found.
    (Functional/SvgImageFieldAltRequiredTest.php, line 44)
  3. I'm not sure why the composer (previous minor) is failing, but that should be split off and handled in a separate issue:
    Your requirements could not be resolved to an installable set of packages.
      Problem 1
        - Root composer.json requires drupal/core-dev 11.1.9 -> satisfiable by drupal/core-dev[11.1.9].
        - composer/composer[2.9.3, ..., 2.9.x-dev] require justinrainbow/json-schema ^6.5.1 -> satisfiable by justinrainbow/json-schema[6.5.1, ..., 6.6.4].
        - drupal/core-dev 11.1.9 requires composer/composer ^2.8.1 -> satisfiable by composer/composer[2.9.3, 2.9.x-dev].
        - drupal/core-dev 11.1.9 requires justinrainbow/json-schema ^5.2 -> satisfiable by justinrainbow/json-schema[5.2.0, ..., 5.x-dev].
        - Conclusion: don't install justinrainbow/json-schema 5.3.1 (conflict analysis result)
        - You can only install one version of a package, so only one of these can be installed: justinrainbow/json-schema[5.2.0, ..., 5.x-dev, 6.5.2, ..., 6.6.4].