Slightly larger one here. :-) The functio theme_calendar_nav_wrapper() in calendar_api.php outputs the header row of the calendar as a row of header cells. However, it does so by passing the theme('table') function an empty body array, which results in a table that contains a tbody element that has no content. a tbody element that does not contain a th element is invalid (X)HTML.

The solution is to either switch that function to use a body row rather than a header row, or beef up theme_table() in core to skip the tbody completely if there are no rows. For now, I think the former is the better option. The following code does that (again, at work so don't have CVS):

function theme_calendar_nav_wrapper($array) {
	$row = array();
	foreach ($array as $element) {
		$row[] = $element;
	}
  return theme('table', array(), array($row));
}
CommentFileSizeAuthor
#4 empty_tbody_4-7.patch2.66 KBm1mic

Comments

karens’s picture

The problem here is that it will produce td elements instead of th elements which makes the css much more complicated to get working correctly. Plus as a regular table row, some themes goof it up by applying the 'odd' style to it. So it needs to be a header row. I'll have to think about another way to do this...

karens’s picture

Crell’s picture

It looks like someone fixed this in Drupal 6 so that theme_table() behaves better when there are no rows defined. Not much help for 4.7 or 5, but it won't be a problem for long. :-)

m1mic’s picture

Title: Mini-calendar header produces invalid code » Table_theme fails XHTML validation on empty tbody elements
Project: Calendar » Drupal core
Version: 4.7.x-1.x-dev » 4.7.x-dev
Component: Code » theme system
Status: Active » Needs review
StatusFileSize
new2.66 KB

This was originally reported as a bug in the Calendar module, but the theme_table() function was the root cause. Backporting the solution from Head. Please see Issue 171461 for more details.

DrupalTestbedBot tested ejhildreth's patch (http://drupal.org/files/issues/empty_tbody_4-7.patch), the patch failed. For more information visit http://testing.drupal.org/node/96

Sorry about that, the patch was incorrectly tested against HEAD and not 4.7.x. We'll work to correct this quickly. --Drupal Testing Team (Robin takes the blame).

susata’s picture

Has anyone come up with a solution for this issue for Drupal 5.x? If so, I would appreciate if someone could please point me in that direction. Thanks!
s.

francoud’s picture

Just had the same problem right yesterday :)

I tried apply this patch (drupal 5.6): http://drupal.org/files/issues/theme_inc_tbody.patch
Documented here: http://drupal.org/node/171461

It solved my problem :))

susata’s picture

francoud, Thanks for the great tip!!! The patch works wonderfully in my 5.5 installation.
s.

m1mic’s picture

I backported the patch that was used in DRUPAL-6 dev cycle to DRUPAL-5-dev. Please see http://drupal.org/node/171461#comment-732368.

susata’s picture

Please forgive the newbie question... Will a patch written for 5-dev be appropriate for 5.5?

Thanks,
s.

Crell’s picture

@susata: Possibly, since point releases only fix bugs or security holes. You want to be running 5.7, though, as there are known security holes in 5.5. The fix is upgrading to 5.7. :-)

susata’s picture

Well, I guess I'll have to stop putting off upgrading from 5.5 (I have never done an upgrade before and am terrified of things breaking).

And then I will also upgrade to your 5.7 fix.

Thank you for providing this fix and thank you for your very wise advice re upgrading.
s.

Crell’s picture

Version: 4.7.x-dev » 4.7.9
Status: Needs review » Fixed

As 4.7 is no longer supported and Drupal 6 and later already have this patch, I guess this can be marked fixed.

Status: Fixed » Closed (fixed)

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