UPDATE: see slightly simpler directions for this issue at #27
#614508: Annotate tracker page with RDFa revealed a bug in rdf_rdfa_attributes() which currently requires a callback function in the RDF mapping to be defined in order to add a content attribute in RDFa. However there are cases like in the tracker issue where we simply want to insert the $data value "as is" in the content attribute. It's equivalent to having a callback function that simply returns the same value as input. We could adapt the logic of rdf_rdfa_attributes() so that when a $data argument is given, it is output as is if we don't have a callback function. However this won't work because in rdf_preprocess_field() we pass the $item['#item'] as $data, and we do so because we must cover the case of where the field item value must be process by a callback function which would be defined in the field RDF mapping definition. To work around this, and in the case where a value $data
has to be inserted in the content attribute without being altered by a callback function, I suggest that the RDF mapping definition simply specifies an empty callback function which we could declare as constant RDF_CALLBACK_PASS
or something along those lines.
Comment | File | Size | Author |
---|---|---|---|
#27 | 642122_rdf_rdfa_attributes_27.patch | 5.37 KB | scor |
#18 | passthrough_642122_18.patch | 6.4 KB | scor |
#16 | passthrough_642122_16.patch | 6.4 KB | scor |
#14 | passthrough_642122_14.patch | 5.6 KB | scor |
#12 | passthrough_642122_4.patch | 1.28 KB | scor |
Comments
Comment #1
scor CreditAttribution: scor commentedThis patch adds an RDF_PASSTHROUGH_CALLBACK flag to rdf.module. This patch also moves the datatype insertion out of the callback condition since it is independent from whether or not we want to use a content attribute. Here is an example of how to use the flag with the amount of comments for a node:
This is the output
<td class="replies" property="sioc:num_replies" content="0" datatype="xsd:integer">0</td>
Comment #2
Dries CreditAttribution: Dries commentedMmm, that looks slightly odd to me, to be honest. I'd prefer consistency over a special case.
Comment #3
scor CreditAttribution: scor commentedIs it the syntax
'callback' => RDF_PASSTHROUGH_CALLBACK,
that you find odd? Regardless we need to have a way to add a content attribute without having a callback function, this is a bug.Alternative 1:
Change the signature of rdf_rdfa_attributes() and have:
Alternative 2:
Define a real passthrough callback function like:
and use it in the mapping definition
Comment #4
scor CreditAttribution: scor commentedpatch for alternative 2 above. Less code changes and less special casing as Dries said. will update #614508: Annotate tracker page with RDFa to make use of this patch.
Comment #5
Stefan Freudenberg CreditAttribution: Stefan Freudenberg commentedThe default callback function is a good idea, though a developer should not have to bother about providing it in the mapping array. My patch provides an alternative and tests for the new case.
We could use the rdf_passthrough function together with the new patch by using it as a default callback instead of directly using the data value which makes the code more legible and elegant. But giving it such a prominent position in our API by naming it rdf_passthrough is not optimal, as it is not really specific to the RDF namespace.
Comment #9
scor CreditAttribution: scor commented@stefan: how do you deal with the case in rdf_preprocess_field() where we always pass a $data value to rdf_rdfa_attributes() because we rely on the RDF mapping definition to know what to do with it?
In this case we don't want the value to appear in a content attribute.
Comment #10
Stefan Freudenberg CreditAttribution: Stefan Freudenberg commentedThen I see no other way but to provide the default callback in the mapping. I am going to adapt the tests to the prior patch. Still I am not so comfortable with the function name but I have not found a way in PHP 5.2 to avoid having it.
Comment #11
scor CreditAttribution: scor commentedTo summarize, here are the 3 cases we need to cover in RDFa:
1. value same as the one in the HTML tag
In this snippet, the value for dc:title is simply the content of the a tag and we don't need to use a
content
attribute. Note that rdf_preprocess_field() unconditionally calls rdf_rdfa_attributes() and relies on the RDF mapping definition to figure out whether we need a content attribute or not (depending on whether there is a callback function or not).2. value different from the one in the HTML tag
In this snippet, we need to convert a date to the proper iso 8601 format using the
date_iso8601
callback function.3. value different from the one in the HTML tag, but no conversion needed (case currently missing)
In this snippet, we do not need to convert the number of comments, but cannot use the content of the
td
tag because it contains extra code which would interfere with the value21
, so it's better to use acontent
attribute with the value 21. We suggest to specify a passthrough callback function in the RDF mapping definition.Comment #12
scor CreditAttribution: scor commentedsame patch as in #4 since Stefan also agreed it's the best approach.
Comment #13
mlncn CreditAttribution: mlncn commentedCode looks good, given the weird thing it has to do, and it doesn't break existing RDFa, but I need example data for the third case to review and the we should have a test to go with it.
Comment #14
scor CreditAttribution: scor commentedtest galore!
Comment #16
scor CreditAttribution: scor commentedThat's a side effect of the updated test_entity mapping definition. updated rdf.test.
Comment #17
mlncn CreditAttribution: mlncn commentedAll good.
Comment #18
scor CreditAttribution: scor commentedrerolling patch
Comment #23
scor CreditAttribution: scor commentednow the testing bot is back, reverting to RTBC per #17.
Comment #26
scor CreditAttribution: scor commentedsetting back to RTBC since the testing bot has given the green light.
Comment #27
scor CreditAttribution: scor commentedWhile working on #614508: Annotate tracker page with RDFa, we realized that the rdf_passthrough approach should not be integrated in rdf_rdfa_attributes() because the case we tried to cover is dependent on the theme layer and should not be handled at the RDF mapping level. It is up to the theme layer to add the appropriate content attribute if necessary, depending on what it outputs in the HTML tag. (see example at #614508-43: Annotate tracker page with RDFa).
This makes this issue much more simplier! Here is the new description which summarizes what the attached patch does (changing the title to reflect this).
Description
#614508: Annotate tracker page with RDFa revealed a bug in rdf_rdfa_attributes() which currently requires a callback function to be defined in the RDF mapping in order to output a datatype attribute in RDFa. However, as illustrated in the case 3 below, there are cases where we want to output a datatype without outputting a content attribute (and instead use the value of the HTML tag). The patch attached improves the logic of
rdf_rdfa_attributes
to support this use case. It also extends the tests to cover the various types of mapping like ObjectProperty and inverse ObjectProperty.To summarize, here are the 3 cases we need to cover in RDFa:
1. Same value as the one in the HTML tag (no callback function)
In this snippet, the value for dc:title is simply the content of the a tag and we don't need to use a
content
attribute.2. Value different from the one in the HTML tag (callback function)
In this snippet, the date was converted to the proper iso8601 format using the
date_iso8601
callback function. The iso8601 date value appears in the content attribute.3. Same value as the one in the HTML tag with datatype. (case currently missing)
In this snippet, we do not need to convert the number (21) but we want to specify its datatype with
datatype="xsd:integer"
.The following snippet is not handled by rdf_rdfa_attributes and should be handled at the theme layer:
In this snippet, we do not need to convert the number of comments, but cannot rely on the value of the
td
tag because it contains extra code which would interfere with the value21
. Here it is recommended to use acontent
attribute with the value 21. rdf_rdfa_attributes() does not support this particular case: the content attribute should be added while building the HTML output, see an example in the tracker module and #614508: Annotate tracker page with RDFa.Comment #28
aspilicious CreditAttribution: aspilicious commentedback to rtbc, green bot light
Comment #29
scor CreditAttribution: scor commentedthis patch includes a small API fix so it's best to get it in before alpha.
Comment #30
webchickI think I'm going to leave these RDF patches for Dries, since he knows this stuff much better and I really don't. But if they're not committed by Sunday or so I'll go ahead and toss 'em in, since your folks' changes always come with tests which make me more inclined to blindly commit them. ;)
Comment #31
Stefan Freudenberg CreditAttribution: Stefan Freudenberg commented+1
Comment #32
scor CreditAttribution: scor commentedI think Sunday has passed!
Comment #33
webchickIt did! But I talked to Dries tonight and he said he would look at these RDF patches tomorrow. I really think that's better since I can't give these a proper QA review myself.
Comment #34
webchickOr not. ;)
I am a bit hesitant to commit this, since I know Dries expressed reservations above, but that seemed to be about the weird magical constant thing, and this new approach does away with that. There are tests to prove that everything's working as it should, and the RDF team seems to think this is pretty important.
Committed to HEAD. Dries, feel free to roll back if this goes against your wishes. Sorry, just trying to tie up all the various loose ends so we have 24 hours for testing.