Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 298347

Classy field wrong structure

$
0
0

Hi, I notice that in Classy theme, the field.html.twig has some issue.

Here is the ref from the drupal core repo for field.html.twig

First of all, in the first "if" part of code we can find

{% if label_hidden %}
  {% if multiple %}
    <div{{ attributes.addClass(classes, 'field__items') }}>
      {% for item in items %}
        <div{{ item.attributes.addClass('field__item') }}>{{ item.content }}</div>
      {% endfor %}
    </div>
  {% else %}
    {% for item in items %}
      <div{{ attributes.addClass(classes, 'field__item') }}>{{ item.content }}</div>
    {% endfor %}
  {% endif %}
{% else %}

in the second section of this part of code we can find

for item in items

but the div inside has

attributes.addClass(classes, 'field__item')

instead of

item.attributes.addClass(classes, 'field__item')

as it should be and as stated here.

going to the second part of this code we find

{% else %}
  <div{{ attributes.addClass(classes) }}>
    <div{{ title_attributes.addClass(title_classes) }}>{{ label }}</div>
    {% if multiple %}
      <div class="field__items">
    {% endif %}
    {% for item in items %}
      <div{{ item.attributes.addClass('field__item') }}>{{ item.content }}</div>
    {% endfor %}
    {% if multiple %}
      </div>
    {% endif %}
  </div>
{% endif %}

and to conclude, in the first part (the "if label_hidden" one) we have a container div with attributes classes only on fields with multiple configuration. In the second part, we have that container div for all our fields and inside this one we have a new container div with "field__items" class (another markup change based on context but probably not necessary).

why first and second part are so different? the markup can be changed to be more consistant.

I have created a patch with a cleaner structure that should work and should be more consistent. (I will attach the patch to the comment below).


Viewing all articles
Browse latest Browse all 298347

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>