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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

scor’s picture

Status: Active » Needs review
FileSize
1.69 KB

This 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:

        'comment_count' => array(
          'predicates' => array('sioc:num_replies'),
          'datatype' => 'xsd:integer',
          'callback' => RDF_PASSTHROUGH_CALLBACK,
        ),

This is the output
<td class="replies" property="sioc:num_replies" content="0" datatype="xsd:integer">0</td>

Dries’s picture

Mmm, that looks slightly odd to me, to be honest. I'd prefer consistency over a special case.

scor’s picture

Is 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:

function rdf_rdfa_attributes($mapping, $data = NULL, $passthrough = NULL) {

Alternative 2:
Define a real passthrough callback function like:

function rdf_passthrough($data) {
  return $data;
}

and use it in the mapping definition

        'comment_count' => array(
          'predicates' => array('sioc:num_replies'),
          'datatype' => 'xsd:integer',
          'callback' => 'rdf_passthrough',
        ),
scor’s picture

FileSize
1.28 KB

patch 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.

Stefan Freudenberg’s picture

FileSize
3.03 KB

The 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.

Status: Needs review » Needs work
Issue tags: -RDF, -RDFa

The last submitted patch failed testing.

Status: Needs work » Needs review

Stefan Freudenberg requested that failed test be re-tested.

Status: Needs review » Needs work
Issue tags: +RDF, +RDFa

The last submitted patch failed testing.

scor’s picture

@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?

        $variables['item_attributes_array'][$delta] = rdf_rdfa_attributes($mapping[$field_name], $item['#item']);

In this case we don't want the value to appear in a content attribute.

Stefan Freudenberg’s picture

Then 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.

scor’s picture

To summarize, here are the 3 cases we need to cover in RDFa:

1. value same as the one in the HTML tag

<a property="dc:title" href="/node/146">A node title</a>

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

<td datatype="xsd:dateTime" content="2009-11-27T17:39:25-06:00" property="sioc:last_reply_date">1 day 20 hours ago</td>

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)

<td datatype="xsd:integer" content="21" property="sioc:num_replies" class="replies">21<br/><a href="/node/149#new">21 new</a></td>

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 value 21, so it's better to use a content attribute with the value 21. We suggest to specify a passthrough callback function in the RDF mapping definition.

scor’s picture

Status: Needs work » Needs review
FileSize
1.28 KB

same patch as in #4 since Stefan also agreed it's the best approach.

mlncn’s picture

Status: Needs review » Needs work

Code 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.

scor’s picture

Status: Needs work » Needs review
FileSize
5.6 KB

test galore!

Status: Needs review » Needs work

The last submitted patch failed testing.

scor’s picture

Status: Needs work » Needs review
FileSize
6.4 KB

That's a side effect of the updated test_entity mapping definition. updated rdf.test.

mlncn’s picture

Status: Needs review » Reviewed & tested by the community

All good.

scor’s picture

rerolling patch

Status: Reviewed & tested by the community » Needs work
Issue tags: -RDF, -RDFa

The last submitted patch failed testing.

Status: Needs work » Needs review

scor requested that failed test be re-tested.

Status: Needs review » Needs work

The last submitted patch, , failed testing.

Status: Needs work » Needs review
Issue tags: +RDF, +RDFa

Re-test of from comment #2380644 was requested by @user.

scor’s picture

Status: Needs review » Reviewed & tested by the community

now the testing bot is back, reverting to RTBC per #17.

Status: Reviewed & tested by the community » Needs review

Re-test of passthrough_642122_18.patch from comment #18 was requested by webchick.

scor’s picture

Status: Needs review » Reviewed & tested by the community

setting back to RTBC since the testing bot has given the green light.

scor’s picture

Title: Allow for RDFa content attribute without callback function » Allow for RDFa datatype attribute without callback function
Status: Reviewed & tested by the community » Needs review
FileSize
5.37 KB

While 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)

<a property="dc:title" href="/node/146">A node title</a>

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)

<td datatype="xsd:dateTime" content="2009-11-27T17:39:25-06:00" property="sioc:last_reply_date">1 day 20 hours ago</td>

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)

<td datatype="xsd:integer" property="sioc:num_replies">21</td>

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:

<td datatype="xsd:integer" content="21" property="sioc:num_replies">21<br/><a href="/node/149#new">21 new</a></td>

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 value 21. Here it is recommended to use a content 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.

aspilicious’s picture

Status: Needs review » Reviewed & tested by the community

back to rtbc, green bot light

scor’s picture

Issue tags: +alpha blocker

this patch includes a small API fix so it's best to get it in before alpha.

webchick’s picture

I 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. ;)

Stefan Freudenberg’s picture

+1

scor’s picture

I think Sunday has passed!

webchick’s picture

It 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.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Or 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.

Status: Fixed » Closed (fixed)
Issue tags: -RDF, -RDFa, -alpha blocker

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