Closed (fixed)
Project:
Drupal core
Version:
7.x-dev
Component:
markup
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
29 Dec 2011 at 15:11 UTC
Updated:
4 Jan 2014 at 01:39 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
johnalbintheme_field() does get a "clearfix" class, but it is conditionally added. See http://api.drupal.org/api/drupal/modules--field--field.module/function/t...
It looks as if the field.tpl.php gets it unconditionally since its hard-coded in the template file. Actually, if the label is inline, I think it might print 2 clearfix classes. Capi, can you confirm that?
Comment #2
barraponto@JohnAlbin yes it does print clearfix twice. I believe it means field.tpl.php shouldn't print it unconditionally. I guess the straightforward patch for Drupal 8 is just removing the clearfix class from field.tpl.php (preprocess logic will insert it if needed).
For Drupal 7 I think we can follow the same strategy, since the template file is not used by default unless it has been copied to the theme folder — then changing the file will have no effect.
Attached are patches for both versions.
Comment #3
barrapontoD7 patch is broken.
Comment #4
njwrigley commentedI'm using the Zen theme and this is causing text to fail to wrap around images which are floated.
If I set the fields to display 'above' then the issue goes away, so the clearfix applied if the field is 'inline' (field-label-inline) appears to be the root cause.
Comment #5
barraponto@njwrigley thanks for the feedback. Please don't change the version since this has been tested and affects the development version of both Drupal and Drupal 8.
Try upgrading Drupal 7 and applying the provided D7 patch, and post feedback on whether it works for you. It would speed up fixing this issue. See http://drupal.org/patch/apply for instructions.
Comment #7
barrapontoRe-roll, trying to make it more explicit. There is some logic for printing 'clearfix' classes in template_preprocess_field:
Theming fields usually call the function implementation in field module. There is also a tpl.php implementation that is never called, it's only there to make designer's lives easier. It will only be used if it is copied to the theme folder. It has a bug though: a hardcoded clearfix class that always prints, and when the condition in template_preprocess_field() applies, it gets printed twice.
<div class="<?php print $classes; ?> clearfix"<?php print $attributes; ?>>My patch just removes that hardcoded class. Anyone currently affected by this bug won't benefit from the patch, since they have already copied the tpl.php file over to their theme (and probably tweaked it further). But this bug will stop biting new users.
Comment #8
barrapontoGo bot!
Comment #9
xjmSo my concern here (as @barraponto and I discussed on IRC) is that the clearfix is only being added to the classes in the preprocess when
#label_displayis'inline', but the template hardcodes it and prints it always.The question is, should the clearfix also be added if the label is not inline?
in the template, and we can possibly backport without any concern. Edit: Hmm, maybe not. Someone might be overriding all of
$classesbut relying on that clearfix.It might also be good to get some manual testing for this in core themes for some fields with hidden, inline, and block labels.
Edit: Oops, crosspost. Testbot will still do the job, though. :)
Edit: Note also that this bug is very easy to work around in a custom theme. You just override the template. So I'm not seeing a strong case for backporting this, even though it's definitely a good fix.
Comment #10
johnalbinNo, it shouldn't. The clearfix class is added there because Drupal has some completely whacky styling for fields with inline labels. It floats the label to the left and makes all the field content shift to the right of the label. IMO, that whole styling should be removed because it's not the styling that 99.9% of sites want for inline labels. They want the label to appear inline with the field content flowing around it.
However, what I just described is a feature request. Anyone care to open one up? It shouldn't stop progress on this legitimate bug.
So, yes, the patch for D8 is just fine. But I disagree with your assessment for the D7 patch; it should be backported. The field.tpl.php file is not even used; core always uses the theme_field() function. The only time field.tpl.php is used is when a themer copies it to their theme in order to override core's theme_field() function. That means it is only a copy of field.tpl.php that is being used on 1000s of production sites. Fixing the original won't break any sites.
Comment #11
xjmWell, in that case. (I think @barraponto might have been trying to say the same thing; I just didn't quite understand.) Thanks @JohnAlbin!
Comment #12
catchCommitted/pushed to 8.x.
John Albin's right that this template is never used in core, so it ought to be viable to backport this.
Comment #13
xjmYep, see the source for field.tpl.php. It's un-used-ness is documented up top.
@barraponto tracked this down yesterday to this issue: #652246: Optimize theme('field') and use it for comment body
Comment #14
barrapontohere is the backport (yes it's the same thing).
Comment #16
barraponto#14: 1388496-field-template-always-prints-clearfix-class_d7.patch queued for re-testing.
Comment #17
xjmRe-TBC.
Comment #18
webchickCool. This initially made me pretty cagey because it's a change to a .tpl.php file, but #10 explains why this is safe for backport.
Committed and pushed to 7.x. Thanks!