Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
The date field currently hard-codes a dc:date in core/modules/datetime/lib/Drupal/datetime/Plugin/Field/FieldFormatter/DatetimeDefaultFormatter.php:126. We need to support the RDF mappings defined by core.
Proposed resolution
Change core/modules/datetime/lib/Drupal/datetime/Plugin/Field/FieldFormatter/DatetimeDefaultFormatter.php to use the proper mappings of core. A good example is the taxonomy field formatter at #1778122-113: Enable modules to inject attributes into field formatters, so that RDF attributes get output.
Remaining tasks
write patch
User interface changes
none
API changes
none
Comment | File | Size | Author |
---|---|---|---|
#17 | interdiff.txt | 962 bytes | ashepherd |
#17 | 2139551-datime_rdfa-17.patch | 4.65 KB | ashepherd |
#15 | 2139551-diff-13-15.txt | 767 bytes | vijaycs85 |
#15 | 2139551-datime_rdfa-15.patch | 4.43 KB | vijaycs85 |
#13 | rdf-datetime_rdfa_support-2139551-13.patch | 4.32 KB | chrisfromredfin |
Comments
Comment #1
djevans CreditAttribution: djevans commentedThe simplest thing seems to be to remove the hardcoded reference to dc:date. Adding RDF mappings to datetime fields then adds the @property attribute to the wrapper
<div>
of each individual<time>
element.This also shouldn't affect any of the property mappings that already exist in core.
Comment #2
djevans CreditAttribution: djevans commentedComment #3
scor CreditAttribution: scor commentedI'd rather add the @property inside the time element since the new field formatters in D8 allow that. See how the taxonomy field formatter does it.
Comment #4
djevans CreditAttribution: djevans commentedOK, @property now belongs to the inner
<time>
element, using a similar approach to the Taxonomy module's LinkFormatter. The comments in template_preprocess_field() also helped.Comment #5
djevans CreditAttribution: djevans commentedComment #6
djevans CreditAttribution: djevans commentedComment #9
djevans CreditAttribution: djevans commentedComment #10
scor CreditAttribution: scor commentedComment #11
chrisfromredfinpatch re-rolled... seems like the filename just changed.
Is there other work to do on this in terms of the actual solution, or is the formatter acceptable as-is?
Comment #12
scor CreditAttribution: scor commentedWe will need test for this one as well, much like the other field formatters.
Comment #13
chrisfromredfinThis patch is the above patch, plus a new test for the datetime_default formatter. TBD is whether or not we need to test the datetime_plain formatter. As of right now it doesn't support RDFa at all, so we're not sure if either (a) the formatter should go away, (b) the formatter should stay as is, and not support RDFa, or (c) we should include support for RDFa in the plain formatter.
Note that it also includes a change to the signature for FieldRdfaTestBase::assertFormatterRdfa() by adding a fifth parameter for $datatype. Probably a better approach here is to pass in $expected_value as an array, rather than take three values in the function signature, but I will leave that to another issue. For now, this is preferred because it won't break other tests.
Comment #14
vijaycs8513: rdf-datetime_rdfa_support-2139551-13.patch queued for re-testing.
Comment #15
vijaycs85missing new param in docblock. Adding in this patch.
Comment #16
scor CreditAttribution: scor commentedThe dc:date came from contrib when the date module was first introduced in core. It should be removed since we now use the attributes that come from config (like this patch already does). The following line also need to be removed:
I've mulled over this for the last couple of weeks and I'm convinced we shouldn't support/worry about this field formatter, I'm not even sure why someone would want to use this field formatter and have RDFa at the same time. I'm not even sure what the purpose of this field formatter is on its own (but that's beyond this issue). Moreover, if someone really want to have RDFa with a similar output as the plain formatter, they could register a custom date format and choose it in the settings of the default date formatter, and get RDFa for free via the time HTML5 element.
Comment #17
ashepherd CreditAttribution: ashepherd commentedAddressed comment #16. Run the datetime test and is passing locally.
Comment #18
scor CreditAttribution: scor commentedLooks good, thanks Adam, djevans, cwells, vijaycs85 for your work on this patch!
Comment #19
catchCommitted/pushed to 8.x, thanks!