My proposal is to add a number of new theme functions, or re-purpose/reuse existing functions, in order to bring consistency (as much as we can) to Drupal core output across modules and templates.

Drupal already does a really good job of this, however there are some places we can improve, so this is really a meta issues for throwing up discussion/ideas and then create specific issues that stem out of the ensuing debate. I've tagged this as HTML5 because this really stemmed from my prototyping for HTML5 in D8 core, although of it is not specific to HTML5.

CommentFileSizeAuthor
#3 theme_datetime.patch1.23 KBEverett Zufelt
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Jeff Burnz’s picture

The first one that really strikes me is our formatting of dates and times.

Our current use of times and dates is rather inconsistent in core, for example lets compare just a couple:

Node:
$variables['date'] = format_date($node->created);
Eventually this is printed in node tpl via $submitted and no markup is added anywhere - its naked and unless RDFa is enabled this carries zero semantics.

Aggregator:
$variables['feed_age'] = t('%age old', array('%age' => format_interval(REQUEST_TIME - $item->timestamp)));
$feed_age is printed in aggregator-summary-item.tpl.php wrapped in span's with a class: <span class="age"><?php print $feed_age; ?></span>

There are quite a few other instances of this sort of inconstancy in aggregator, and of course comment tpl does essentially the same thing as node.

I think we have a use case here for a theme_datetime() function. This would provide a simple wrapper with attributes. This will allow much easier global override of markup for dates and times, for example if we want to use XHTML we can use a span, if we want to use HTML5 we can use time + the time attributes such as pubdate, datetime etc.

In HTML5 we can use the <time> element. Here's a bit of a write up about it and if you're really hard core read the spec.

Note that we already have a theme_date which is used to returns HTML for a date selection form element, so that namespace is taken.

Everett Zufelt’s picture

@Jeff

What are your ideas around the types of attributes that would be passed to theme_datetime()?

My thoughts would be that we pass in a unix timestamp We also need to be able to pass in at least a boolean value for pubdate, but might optionally allow a date formate type (including custom) to be passed in.

This would be sufficient to do html5 time elements
if ($pubdate) {
$element['attributes']['pubdate'] = 'pubdate';
}

$datetime = format_date($timestamp, 'custom', 'y-m-d h:i');

$element['attributes']['datetime'] = $datetime;

$datetime_content = format_ate($timestamp, $format_type, $format_custom);

This clearly gets more difficult with localization and timezones, but since the code is already in core to do this it can just be abstracted into the theme_datetime() function.

Everett Zufelt’s picture

Status: Active » Needs review
FileSize
1.23 KB

As a starting point. Likely should be spinned off into to its own issue.

Everett Zufelt’s picture

Jacine’s picture

Status: Needs review » Active

Can we close this? We already have an issue for the date stuff, and that's really the only solid idea brought forth in here. I completely agree that we'll need to add more theme functions, but I think we'll be better off creating issues for them as we think of them. Let me know what you think.

Jeff Burnz’s picture

Status: Active » Closed (duplicate)