Duplicate field and field label classes

Created on 4 February 2023, over 1 year ago
Updated 13 December 2023, 7 months ago

Problem/Motivation

Classes for field and field label are added twice on the elements.

Issue was introduced in https://www.drupal.org/project/fences/issues/1343578 β†’

Steps to reproduce

1. Create a field (e.g. text field) on an entity (e.g. a Node).
2. Using fences, add classes to the field, label, and item.
3. Create a Node and populate the field created in Step 1.
4. View the node and inspect elements of the field created in Step 1.

Proposed resolution

Patch to remove code causing the duplication.

Remaining tasks

  1. Write a tests for duplicate classes
  2. Write a fix
  3. Review
  4. Merge

User interface changes

None

API changes

None

Data model changes

None

πŸ› Bug report
Status

Needs work

Version

3.0

Component

Code (fences)

Created by

πŸ‡ΊπŸ‡ΈUnited States fskreuz

Live updates comments and jobs are added and updated live.
  • 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.

Sign in to follow issues

Comments & Activities

  • Issue created by @fskreuz
  • Status changed to Needs review over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States fskreuz
  • Status changed to Needs work over 1 year ago
  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    Thank you @fskreuz, sorry I wasn't able to reproduce this yet. Which theme are you using?
    Could you write a test that shows this issue please? That way we can prove the issue exists, is reproducible and we can prevent it in the future.

  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica
  • πŸ‡ΊπŸ‡ΈUnited States fskreuz

    @Anybody The theme I use is based on stable9. I am not able to write tests at the moment.

    But to add more info, it's this bit of code in `fences_preprocess_field()` that's causing the issue. Two separate issues (linked, see sidebar), possibly not aware of each other and solving separate issues, merged and duplicated functionality. I hope this helps someone.

        // Prevent adding empty classes:
        if (!empty($fences_config['fences_field_classes'])) {
          $fences_field_classes = explode(' ', $fences_config['fences_field_classes']);
          foreach ($fences_field_classes as $class) {
            // Add classes from setting:
            $vars['attributes']['class'][] = $class;
          }
        }
    
        if (!empty($fences_config['fences_label_classes'])) {
          $fences_field_classes = explode(' ', $fences_config['fences_label_classes']);
          foreach ($fences_field_classes as $class) {
            // Add classes from setting:
            $vars['title_attributes']['class'][] = $class;
          }
        }
        if (!empty($fences_config['fences_field_classes'])) {
          $vars['attributes']['class'][] = $fences_config['fences_field_classes'];
        }
        if (!empty($fences_config['fences_label_classes'])) {
          $vars['title_attributes']['class'][] = $fences_config['fences_label_classes'];
        }
    
    
  • πŸ‡ΊπŸ‡ΈUnited States rlnorthcutt Austin, TX

    I can confirm that these duplicate classes are happening, but it seems to be only on the "Field Tag" classes, not all of them.

    For example, here is the configuration for my "Body" field:

    And here is the output:

    Clearing the cache does no good, and resaving the settings does no good. Note that I have another field (taxonomy) with "Field Tag" classes, but those are not duplicated.

  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    @rlnorthcutt my assumption is, that in this case the classes do not run through Drupal Attribute functionality, which should make them unique. Perhaps they are just passed as array, while they are handled correctly in other cases. Perhaps that brings us on the right track.

    But we have to be 100% sure the specific cases are not caused by a custom / contrib theme, please always compare to a core theme. Which theme(s) did you try?

Production build 0.69.0 2024