I just realized that the HTML output generated by certain field formatters interferes with the RDFa parsing, producing some inconsistent RDF. To explain, let's look at 2 examples.

Example 1: image field
Create an article with an image attached to it.

Full node:

<div class="field field-name-field-image field-type-image field-label-hidden clearfix">
  <div class="field-items">
    <div rel="rdfs:seeAlso" class="field-item even">
      <img src="http://localhost/image/generate/large/public/field/image/2009iswc.png"/>
    </div>
  </div>
</div>

Equivalent RDF: <> rdfs:seeAlso <http://localhost/image/generate/large/public/field/image/2009iswc.png>

Teaser:

<div class="field field-name-field-image field-type-image field-label-hidden clearfix">
  <div class="field-items">
    <div rel="rdfs:seeAlso" class="field-item even">
      <a href="/node/1"><img src="http://localhost/image/generate/medium/public/field/image/2009iswc.png"/></a>
    </div>
  </div>
</div>

Equivalent RDF: <> rdfs:seeAlso <http://localhost/node/1>

The RDF produced by the teaser is not the same as the RDF produced by the full node of the same article. The full node RDFa is good, while the teaser links to itself which is not what we expect. This glitch is due to the @href of the a tag wrapping the img tag (RDFa parsers take the first @href/@src available in the tag containing the @rel, or in the first children tag containing @href/@src).

Example 2: file field
Add a file field to a content type and create node with a txt file attached to it.

<div class="field field-name-field-file field-type-file field-label-above clearfix">
  <div class="field-label">file: </div>
  <div class="field-items">
    <div rel="rdfs:seeAlso" class="field-item even">
      <span class="file">
        <img src="/modules/file/icons/text-plain.png" title="text/plain"/>
        <a href="http://localhost/sites/default/files/swcambridge-20091208.txt">swcambridge-20091208.txt</a>
      </span>
    </div>
  </div>
</div>

Equivalent RDF:

<> rdfs:seeAlso <http://localhost/modules/file/icons/text-plain.png>
<> rdfs:seeAlso <http://localhost/sites/default/files/swcambridge-20091208.txt>

Here, the problem is that the icon for the attachment text-plain.txt is picked up by the RDFa chaining: because the last div tag does not contain any @href, @src or @resource, the objects of the mapping rdfs:seeAlso are all the children tags containing either @href/@src.

Conclusion
This only affects the fields containing a link to another resource (aka of type owl:ObjectProperty) like image and file, but does not affect text or numeric type fields.

One way to solve this is by adding a @resource attribute with the url of the file/image in the same div as the rel attribute:

<div class="field field-name-field-file field-type-file field-label-above clearfix">
  <div class="field-label">file: </div>
  <div class="field-items">
    <div rel="rdfs:seeAlso" resource="http://localhost/sites/default/files/swcambridge-20091208.txt" class="field-item even">
      <span class="file">
        <img src="/modules/file/icons/text-plain.png" title="text/plain"/>
        <a href="http://localhost/sites/default/files/swcambridge-20091208.txt">swcambridge-20091208.txt</a>
      </span>
    </div>
  </div>
</div>

Comments

Anonymous’s picture

StatusFileSize
new1.07 KB

This patch checks to see whether the field has a File ID. If it does, it sets the resource attribute to the file url.

Let me know if there are any problems with this approach, I will start working on the test for this issue.

scor’s picture

Status: Active » Needs work
+++ modules/rdf/rdf.module	8 Jan 2010 16:19:10 -0000
@@ -453,6 +453,14 @@ function rdf_preprocess_field(&$variable
+      if ($item['fid']) {
+        $variables['item_attributes_array'][$delta]['resource'] = file_create_url($item['uri']);

- we should isset() or !empty() here to avoid notices when $item['fid'] is not defined.

- how about testing for $item['uri'] directly in the if condition instead of $item['fid']?

This is the approach that first came to my mind too, and it works well for file/image fields, not sure yet whether we should do something more generic, or let the contrib module implementing new field formatter to deal with this situation like we do here. For instance, a more generic approach would be to let fields specify the resource there describing by adding a resource key in each item array, and rdf.module would use that value if it exists. However this would be an API change which a bit late at this stage, and we should probably go with the approach of #1.

Powered by Dreditor.

Anonymous’s picture

StatusFileSize
new4.55 KB

Yeah, I realized the isset issue when I started writing the test for it.

The patch has the fix for that as well as a test which uploads both an image and a text file.

If this goes in as an API change, it would allow for the use of hash URIs as well, which would be a bonus.

scor’s picture

Status: Needs work » Needs review

sending patch for testing.

Status: Needs review » Needs work

The last submitted patch, rdf_file-resource-attr_678594-2.patch, failed testing.

Anonymous’s picture

StatusFileSize
new4.54 KB

I changed the conditional to test for $item['uri']. This may also catch link fields if link module changed its array key from 'url' to 'uri', but that shouldn't cause problems.

This patch will not currently pass tests. The test for the rel property on field_image is dependent on the change to the rdf mapping in the standard install profile, as detailed in this issue #632484: Update the default profile with the proper RDF mapping.

Once that patch is committed, this should be good to go.

scor’s picture

Status: Needs work » Needs review

setting for review.

Anonymous’s picture

StatusFileSize
new3.38 KB

EDIT: WRONG PATCH

Anonymous’s picture

StatusFileSize
new5.3 KB

Here is a patch that sets the @resource to the resized image if there is an image style set for the field.

scor’s picture

Title: RDFa does not work with some field formatters » Fix RDFa markup for file/image formatters
Status: Needs review » Needs work

Let's merge #642596: Annotate images with RDFa 'typeof' with this issue given they're touching the same code now.

Anonymous’s picture

StatusFileSize
new5.18 KB

Good idea, the two are now merged.

aspilicious’s picture

Status: Needs work » Needs review

run bot

scor’s picture

Status: Needs review » Needs work
+++ modules/rdf/rdf.module	17 Jan 2010 22:04:03 -0000
@@ -595,6 +608,13 @@ function rdf_field_attach_view_alter(&$o
+  $variables['attributes']['typeof'] = 'foaf:Image';

We should add foaf:Image as an array instead of a string so it's more compatible with other modules willing to add other values to the attribute.

+++ modules/rdf/rdf.test	17 Jan 2010 22:04:06 -0000
@@ -116,6 +116,64 @@ class RdfMarkupTestCase extends DrupalWe
+    $this->drupalLogin($admin_user);
+        ¶
+    $langcode = LANGUAGE_NONE;
+    $bundle_name = "article";
+    ¶
+    // Create file field.

some whitespaces to remove at end of lines (there are more than above).

This review is powered by Dreditor.

Anonymous’s picture

StatusFileSize
new5.36 KB

This should fix all the whitespace and uses an array for foaf:Image

Anonymous’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, rdf_file-resource-attr_678594-14.patch, failed testing.

scor’s picture

+++ modules/rdf/rdf.module	21 Jan 2010 09:31:51 -0000
@@ -595,6 +608,14 @@ function rdf_field_attach_view_alter(&$o
+  dpm($variables);

debugging cruft code

+++ modules/rdf/rdf.module	21 Jan 2010 09:31:51 -0000
@@ -694,5 +715,4 @@ function theme_rdf_metadata($variables) 
   return $output;
-}
-
+}

this change is not necessary

Anonymous’s picture

Status: Needs work » Needs review
StatusFileSize
new5.64 KB

Whoops on the debug message. Here is the new patch.

scor’s picture

Status: Needs review » Reviewed & tested by the community

This is ready. thanks Lin.

dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Thanks.

Status: Fixed » Closed (fixed)

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

scor’s picture

Status: Closed (fixed) » Needs work
+++ modules/rdf/rdf.module	21 Jan 2010 16:37:27 -0000
@@ -595,6 +608,13 @@ function rdf_field_attach_view_alter(&$o
 /**
+ * Implements MODULE_preprocess_HOOK().
+ */
+function rdf_preprocess_image(&$variables) {
+  $variables['attributes']['typeof'] = array('foaf:Image');
+}
+

I think we ought to add a line of explanation here to explain why we're not using the usual entity type to store this foaf:Image type. Image does not have its own entity type or bundle, and therefore we cannot store it like the rest of the mappings. The closest entity is file which has a file bundle. I wonder if an image bundle would have made sense, but that's too late for core.

mlncn’s picture

Version: 7.x-dev » 8.x-dev
Assigned: Unassigned » mlncn
Category: bug » task
Status: Needs work » Needs review
StatusFileSize
new558 bytes

Here is a comment-only patch to address this. Drupal 8 first but should apply to Drupal 7.

xjm’s picture

Status: Needs review » Needs work
Issue tags: +Novice

Tagging as novice for the task of rerolling the Drupal 8.x patch on account of #22336: Move all core Drupal files under a /core folder to improve usability and upgrades.

If you need help rerolling this patch, you can come to core office hours or ask in #drupal-gitsupport on IRC.

kathyh’s picture

Status: Needs work » Needs review
StatusFileSize
new578 bytes

Updated for #24 - D8 /core

xjm’s picture

Component: rdf.module » documentation
Status: Needs review » Reviewed & tested by the community

More properly a docs issue? Or no since it's an inline comment? Looks good to me in either case.

catch’s picture

Status: Reviewed & tested by the community » Needs work

Docs change looks fine but dreditor says mapping is bleeding over 80 chars.

xjm’s picture

Status: Needs work » Reviewed & tested by the community

@catch: Update dreditor. :) Old versions counted the patch margin in the char limit.

xjm’s picture

StatusFileSize
new13.79 KB
new13.91 KB
catch’s picture

Version: 8.x-dev » 7.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)
Issue tags: +Needs backport to D7

Hmm my dreditor disagrees but those screenshots don't lie.

Committed/pushed to 8.x. This wasn't tagged for backport but looks like it should be.

dave reid’s picture

Version: 7.x-dev » 8.x-dev
Status: Patch (to be ported) » Reviewed & tested by the community
Issue tags: -Needs backport to D7

@scor: Maybe you could help us look at http://drupal.org/project/file_entity and see if we need additional RDF there as we do support file 'bundles' there (e.g. 'image', 'audio', 'video').

xjm’s picture

Version: 8.x-dev » 7.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)
Issue tags: +Needs backport to D7

Everyone loves a crosspost!

oriol_e9g’s picture

Status: Patch (to be ported) » Needs review
StatusFileSize
new557 bytes

Rolled for D7

scor’s picture

Status: Needs review » Reviewed & tested by the community

thanks for the backport @oriol_e9g

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed to 7.x. Thanks!

Status: Fixed » Closed (fixed)
Issue tags: -RDF, -Novice, -Needs backport to D7

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