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.

CommentFileSizeAuthor
#2 fieldclassfixes-2941157-2.patch914 byteshongpong

Comments

HongPong created an issue. See original summary.

hongpong’s picture

Status: Active » Needs review
StatusFileSize
new914 bytes

Yes 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.

jonmcl’s picture

Yes, 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.

  • HongPong committed c2f5943 on 8.x-6.x
    Issue #2941157 by HongPong: custom class does not appear on body field...

  • HongPong committed ea47ff0 on 8.x-5.x
    Issue #2941157 by HongPong: custom class does not appear on body field...
hongpong’s picture

Version: 8.x-6.x-dev » 8.x-5.x-dev
Status: Needs review » Fixed

Thanks JonMcL. I applied the patch to 8.x-6.x and backported it to 8.x-5.x .

hongpong’s picture

Version: 8.x-5.x-dev » 8.x-6.x-dev
cumhur’s picture

Dear 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

hongpong’s picture

Merhaba 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.

cumhur’s picture

Merhaba :)
I tested and looks good
Çok teşekkür

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.