When trying to set up a class for the body text field, the custom value is not applied. This is on a zurb_foundation subtheme, although the active zurb_foundation templates/field.html.twig does not seem to be the source of the problem. The element in question has <div{{ attributes }}> on stable theme, and <div{{ attributes.addClass(classes) }}> in equivalent zurb_foundation.
I switched over to Bartik theme and the field formatter class does appear as expected on the body. bartik uses classy/templates/field/field--text-with-summary.html.twig which inherits from field--text.html.twig which only has {% set attributes = attributes.addClass('clearfix', 'text-formatted') %} and then inherits field.html.twig.
it's not clear to me why this would be a problem: <div{{ attributes.addClass(classes) }}> when <div{{ attributes }}> works fine.
Looking deeper at zurb_foundation.theme I have a feeling the problem is around line 114:
// Add class to a specific fields across content types.
switch ($variables['element']['#field_name']) {
case 'body':
$classes = array('body');
break;
After all that seems like it would overwrite anything handed into that classes array beforehand and should more properly be
$classes[] = 'body';
similar to line 143 / 147. (Although I can agree it would make sense to remove the text-secondary on 143 #2940608: Remove class "text-secondary" from teasers ) Will report back here if this fixes it.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | fieldclassfixes-2941157-2.patch | 914 bytes | hongpong |
Comments
Comment #2
hongpong commentedYes this fix works. I am also submitting changes for
case 'field_date', case 'field_link' to merely add (and not replace) text-content , as well as case 'field_image' to merely add $classes[] = 'image' and not replace all other classes. This is all happening in the same area and I personally don't want this thing to shave off other classes.
Comment #3
jonmcl commentedYes, please!
Removing previously created class attribute values from 'field_image' was a big problem for me as I am trying to use the blazy module which is dependent on it's own class values being sent to the field template. I am using 'field_image' as a media entity field and the blazy field formatter.
The patch at #2 worked well for me.
Comment #6
hongpong commentedThanks JonMcL. I applied the patch to 8.x-6.x and backported it to 8.x-5.x .
Comment #7
hongpong commentedComment #8
cumhur commentedDear HongPong ,
why dont you apply this patch before the new dev version
please check
https://www.drupal.org/project/zurb_foundation/issues/2895757
best regards
Comment #9
hongpong commentedMerhaba cumhur :)
I agree #2895757: STARTER installs outdated version of Foundation (6.3.1 to 6.4.1) is an important issue. However this issue was a much more simple one to address and safer to apply. I hope that other zurb_foundation developers can test 2895757 more before we commit it, since it will affect a lot of different aspects of how the websites work. In the next week or two.
Comment #10
cumhur commentedMerhaba :)
I tested and looks good
Çok teşekkür