Add a tiny bit of state magic in the image.module and hide the Title and Alt groups when the related form items are disabled

Created on 19 February 2013, about 12 years ago
Updated 8 April 2025, 9 days ago

Caution, this is not a simple issue to work on, its category of "normal" is not the difficulty, but a measure of its impact .

Problem/Motivation

Image fields have a Title and Alt sub-fields. Both sub-fields are optional and translatable, but enabling/disabling each sub-field does not show/hide the corresponding translation controls. This is confusing, especially because Alt is enabled by default, but Title is not.

Proposed resolution

  1. When editing an image field, use Form API states to hide the Alt checkbox in the Translatable elements list when the Enable Alt field checkbox is unchecked.
  2. When editing an image field, use Form API states to hide the Title checkbox in the Translatable elements list when the Enable Title field checkbox is unchecked.
  3. When editing an image field, display a message ("Disabled fields are not shown. Please first enable the fields you need to make translatable.") below the Translatable elements list if any Translatable elements checkboxes are being hidden.
  4. On the Content language settings page at admin/config/regional/content-language, hide the Alt checkbox if Enable Alt field is unchecked.
  5. On the Content language settings page at admin/config/regional/content-language, hide the Title checkbox if Enable Title field is unchecked.
  6. On the Content language settings page, display a message ("Disabled fields are not shown. Please first enable the fields you need to make translatable.") if any checkboxes are being hidden.

Note that testbot cannot run front-end tests automatically (see #2232271: [Meta] Use Behat for validation testing or #2229187: SiteEffect: Automated frontend regression testing , also #825436: Create selenium-RC PIFR plugin for full functional testing ).

Aside: should this issue be split into two?

It's been suggested the issue be split into two issues: one to change the image field edit page, and one to change the Content language page.

The problem with splitting into two issues is that whichever one is fixed first might be broken by trying to fix the other, and we wouldn't know because we don't have tests (this happened at some point in working on this issue).

Remaining tasks

  • Decide whether to postpone this issue until we have automatic front-end tests.
  • Write front-end tests.
  • Show/hide checkboxes on the image field edit page, and announce this to screenreaders.
  • Show/hide checkboxes on the Content language settings page, and announce this to screenreaders.
  • Display a warning when checkboxes are being hidden on the Content language settings page.
  • Usability review.

Steps to reproduce

  1. Install a fresh Drupal 8.0 site using the Standard install profile (drush -y site-install standard).
  2. Enable the Content Translation module (drush -y pm-enable content_translation).
  3. Go to admin/config/regional/language and add a second language.
  4. Go to admin/structure/types/manage/article/fields/node.article.field_image.
    1. There is a checkbox labeled "Enable Alt field". It is checked by default.
    2. There is a checkbox group titled "Translatable elements", containing a checkbox labeled "Alt". It is checked by default.
    3. There is a checkbox labeled "Enable Title field". It is unchecked by default.
    4. Expected behavior:
      1. There is no checkbox labeled "Title" in the "Translatable elements" checkbox group. There is a message saying "Disabled fields are not shown. First enable the fields before changing their translatable setting."
    5. Actual behavior:
      1. There is a checkbox group titled "Translatable elements", containing a checkbox labeled "Title". It is checked by default.
  5. Uncheck the checkbox labeled "Enable Alt field".
    1. Expected behavior:
      1. The checkbox labeled "Alt" in the "Translatable elements" checkbox group disappears.
      2. The message "Disabled fields are not shown. First enable the fields before changing their translatable setting." stays visible.
    2. Actual behavior:
      1. The checkbox labeled "Alt" in the "Translatable elements" checkbox group stays visible.
      2. No message is shown.
  6. Check the checkbox labeled "Enable Alt field".
    1. Expected behavior:
      1. A checkbox labeled "Alt" in the "Translatable elements" checkbox group appears. It is checked by default.
      2. The message "Disabled fields are not shown. First enable the fields before changing their translatable setting." stays visible.
    2. Actual behavior:
      1. The checkbox labeled "Alt" in the "Translatable elements" checkbox group stays visible.
      2. No message is shown.
  7. Check the checkbox labeled "Enable Title field".
    1. Expected behavior:
      1. A checkbox labeled "Title" in the "Translatable elements" checkbox group appears. It is checked by default.
      2. The message "Disabled fields are not shown. First enable the fields before changing their translatable setting." disappears.
    2. Actual behavior
      1. The checkbox labeled "Title" in the "Translatable elements" checkbox group remains visible.
      2. No message is shown.
  8. Uncheck the checkbox labeled "Enable Title field".
    1. Expected behavior:
      1. The checkbox labeled "Title" in the "Translatable elements" checkbox group disappears.
      2. The message "Disabled fields are not shown. First enable the fields before changing their translatable setting." appears.
    2. Actual behavior
      1. The checkbox labeled "Title" in the "Translatable elements" checkbox group remains visible.
      2. No message is shown.
  9. Check the checkbox labeled "Enable Title field".
  10. Click Save configuration.
  11. Go to admin/config/regional/content-language. In the Custom language settings checkbox group, check Content. In the Content table, check the Translatable checkbox for the Article content type.
    1. A list of fields available for translation appears.
    2. Under "Article" -> "Image", the "File" checkbox is unchecked.
    3. Under "Article" -> "Image", the "Alt" checkbox is checked.
    4. Under "Article" -> "Image", the "Title" checkbox is checked.
    5. No message is shown.
  12. Go to admin/structure/types/manage/article/fields/node.article.field_image.
  13. Uncheck the checkbox labeled "Enable Title field".
  14. Uncheck the checkbox labeled "Enable Alt field".
  15. Click Save configuration.
  16. Go to admin/config/regional/content-language. In the Custom language settings checkbox group, check Content. In the Content table, check the Translatable checkbox for the Article content type.
    1. A list of fields available for translation appears.
    2. Under "Article" -> "Image", the "File" checkbox is unchecked.
    3. Expected behavior:
      1. Under "Article" -> "Image", there is no "Alt" checkbox.
      2. Under "Article" -> "Image", there is no "Title" checkbox.
      3. The message "Disabled fields are not shown. First enable the fields before changing their translatable setting." is shown.
    4. Actual behavior:
      1. Under "Article" -> "Image", the "Alt" checkbox is checked.
      2. Under "Article" -> "Image", the "Title" checkbox is checked.
      3. No message is shown.

User interface changes

  • When editing image field settings:
    • Hide the Alt checkbox in the Translatable elements list when the Enable Alt field checkbox is unchecked.
    • Hide the Title checkbox in the Translatable elements list when the Enable Title field checkbox is unchecked.
    • Display a message when a checkbox is being hidden from the Translatable elements list.
  • On the Content language settings page:
    • Hide the Alt checkbox in the list of fields when the Enable Alt field checkbox is unchecked in the field settings.
    • Hide the Title checkbox in the list of fields when the Enable Title field checkbox is unchecked in the field settings.
    • Display a message when a checkbox is being hidden from the list of fields.

API changes

None.

(If problems are discovered in the config storage, that will be filed in a separate issue)

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component

content_translation.module

Created by

🇺🇸United States yesct

Live updates comments and jobs are added and updated live.
  • Usability

    Makes Drupal easier to use. Preferred over UX, D7UX, etc.

  • D8MI

    (Drupal 8 Multilingual Initiative) is the tag used by the multilingual initiative to mark core issues (and some contributed module issues). For versions other than Drupal 8, use the i18n (Internationalization) tag on issues which involve or affect multilingual / multinational support. That is preferred over Translation.

  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

  • Accessibility

    It affects the ability of people with disabilities or special needs (such as blindness or color-blindness) to use Drupal.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇳🇿New Zealand quietone

    Triaged for Bug Smash. I tested on 11.x yesterday and the problem exists. There hasn't been work here in 9 1/2 suggesting that the community is fine with the current behavior.

    There are many tags here, so I will not add more now. But this will need an Issue Summary update and conversion to an MR.

    And definitely read the first sentence of the issue summary before working on this!

Production build 0.71.5 2024