Problem/Motivation
The RDFa generated by core's RDF module relies on the structure of the HTML—the nesting of theme_field's output inside node.tpl.php's output—to associate the property with its subject entity. This works when an entity is viewed using the entity template, as on the node page.
However, in other cases such as Views, Panels (and I presume D8's Blocks Everywhere), you can't assume that rendering will happen this way. The HTML for a field might sit within the entity's div... or it might be off in a sidebar by itself, or inside a different entity's div. This is also true if a site developer alters the render array to move field's out of their containing divs (a use case JohnAlbin brought up at DrupalCon London).
The problem here is that we depend on an implicit relationship between the field and the entity which is inferred from HTML structure... we don't explicitly state that relationship.
This leads to metacrap when using RDFa and Views/Panels. It has been documented in an issue in the Views queue.
An example
There is a View that shows a list of events, including the location of the event. Locations can be reused across events, so they are handled as their own entity, which has a street address field. The fields used for the view are Event name, Location name, and Location street address. (For the sake of argument, the title is a real field handled by the field system)
Here are the two objects that you should get from the RDFa:
example.org/event/1
- type = schema.org/Event
- schema.org:name = Black Mark release party
- schema.org:location = example.org/location/1
example.org/location/1
- type = schema.org/PostalAddress
- schema.org:name = Brillobox
- schema.org:streetAddress = 4401 Penn Ave.
Instead, what you get is:
example.org/views-page
- schema.org:name = Black Mark release party
- schema.org:name = Brillobox
- schema.org:streetAddress = 4401 Penn Ave.
Proposed resolution
Explicitly state that the field is a property of the entity.
I've done this in Microdata module using the itemref attribute which the microdata syntax provides. While this doesn't add the relationship between the event and it's location, it does ensure that the properties of the two objects don't get mashed up into metacrap.
For example, the location looks as follows in Microdata:
<meta itemscope="" itemtype="http://schema.org/PostalAddress" itemref="md2 md3" />
...
<div class="field">
<div class="field-items" id="md2">
<div class="field-item" itemprop="name">
Brillobox
</div>
</div>
</div>
...
<div class="field">
<div class="field-items" id="md3">
<div class="field-item" itemprop="streetAddress">
4104 Penn Avenue
</div>
</div>
</div>
...
While RDFa has no support for itemref (and the editor had no intention of introducing it the last time we discussed it), we could use a different feature of RDFa to do approximately the same thing. We could add the about attribute to each field.
<meta typeof="http://schema.org/PostalAddress" about="http://example.org/location/1" />
...
<div class="field" about="http://example.org/location/1">
<div class="field-items">
<div class="field-item" property="schema:name">
Brillobox
</div>
</div>
</div>
...
...
<div class="field" about="http://example.org/location/1">
<div class="field-items">
<div class="field-item" property="schema:streetAddress">
4104 Penn Avenue
</div>
</div>
</div>
...
Downside
The downside of this is that we pepper our source code with the full URI of the entity, once for each field. I do believe this will lead the frontend performance folks to chuck tomatos at us.
Remaining tasks
Discuss ramifications / devise plan
Comments
Comment #1
Anonymous (not verified) commentedComment #2
scor commentedTo solve this, I suggest to make the approach described in #1778122-4: Enable modules to inject attributes into field formatters, so that RDF attributes get output to only be enabled in the context of an entity template rendering when we know all elements are in place, and disabled otherwise to avoid generating wrong RDFa markup. Views could still do its own thing, but at least the default behavior of field formatters would not interfere.
Comment #3
Anonymous (not verified) commentedDidn't the RDFa WG introduce something like microdata's itemref? If they did, then we can use that like I did with microdata module.
Comment #4
scor commentedWith #1778122: Enable modules to inject attributes into field formatters, so that RDF attributes get output, we're only outputting RDFa when fields are rendered as part of their entity and when hook_entity_prepare_view() is fired. So any field rendered outside of entity_view() will not have any RDFa markup. I just confirmed that in views for example.
I don't think core should get into the business of providing RDFa for all the combinations of configurations that someone can come up with views. A new issue should be open in contrib to add RDFa to views.
I'm closing this bug report since we're no longer outputting RDFa outside the context of entity_view(). Please re-open if I miss something.
Comment #5
Anonymous (not verified) commentedFor one thing, this ignores Panels. Considering that one of the major pushes for WSCCI was to enable Panels like editing (even though it didn't end up making it in to core), I think ignoring the Views/Panels use case makes RDF module useless to most sites.
Also, we don't need to open a new issue. There's been an open issue to handle RDFa in Views since 2010, as I linked to in the issue summary.... #870722: Support for RDFa.
As I am resigning as a maintainer of this module, I will not be adding any further objections.
Comment #6
Anonymous (not verified) commented