Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal-3174996
Manage
Activity
Members
Labels
Plan
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Issue forks
drupal-3174996
Commits
5c057dfe
Commit
5c057dfe
authored
15 years ago
by
Dries Buytaert
Browse files
Options
Downloads
Patches
Plain Diff
- Patch
#678594
by linclark: fixed RDFa markup for file/image formatters.
parent
9e2b5880
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
modules/rdf/rdf.module
+20
-1
20 additions, 1 deletion
modules/rdf/rdf.module
modules/rdf/rdf.test
+58
-0
58 additions, 0 deletions
modules/rdf/rdf.test
with
78 additions
and
1 deletion
modules/rdf/rdf.module
+
20
−
1
View file @
5c057dfe
...
...
@@ -452,6 +452,19 @@ function rdf_preprocess_field(&$variables) {
if
(
!
empty
(
$mapping
)
&&
!
empty
(
$mapping
[
$field_name
]))
{
foreach
(
$element
[
'#items'
]
as
$delta
=>
$item
)
{
$variables
[
'item_attributes_array'
][
$delta
]
=
rdf_rdfa_attributes
(
$mapping
[
$field_name
],
$item
);
// If this field is an image, RDFa will not output correctly when the
// image is in a containing 'a' tag. If the field is a file, RDFa will
// not output correctly if the filetype icon comes before the link to
// the file. We correct this by adding a resource attribute to the div if
// this field has a URI.
if
(
isset
(
$item
[
'uri'
]))
{
if
(
isset
(
$element
[
$delta
][
'#image_style'
]))
{
$variables
[
'item_attributes_array'
][
$delta
][
'resource'
]
=
image_style_url
(
$element
[
$delta
][
'#image_style'
],
$item
[
'uri'
]);
}
else
{
$variables
[
'item_attributes_array'
][
$delta
][
'resource'
]
=
file_create_url
(
$item
[
'uri'
]);
}
}
}
}
}
...
...
@@ -594,6 +607,13 @@ function rdf_field_attach_view_alter(&$output, $context) {
}
}
/**
* Implements MODULE_preprocess_HOOK().
*/
function
rdf_preprocess_image
(
&
$variables
)
{
$variables
[
'attributes'
][
'typeof'
]
=
array
(
'foaf:Image'
);
}
/**
* Wraps a template variable in an HTML element with the desired attributes.
*
...
...
@@ -695,4 +715,3 @@ function theme_rdf_metadata($variables) {
}
return
$output
;
}
This diff is collapsed.
Click to expand it.
modules/rdf/rdf.test
+
58
−
0
View file @
5c057dfe
...
...
@@ -116,6 +116,64 @@ class RdfMarkupTestCase extends DrupalWebTestCase {
$this
->
assertEqual
(
$expected_attributes
,
$attributes
);
}
/**
* Ensure that file fields have the correct resource as the object in RDFa
* when displayed as a teaser.
*/
function
testAttributesInMarkupFile
()
{
// Create a user to post the image.
$admin_user
=
$this
->
drupalCreateUser
(
array
(
'edit own article content'
,
'revert revisions'
,
'administer content types'
));
$this
->
drupalLogin
(
$admin_user
);
$langcode
=
LANGUAGE_NONE
;
$bundle_name
=
"article"
;
// Create file field.
$file_field
=
'file_test'
;
$edit
=
array
(
'_add_new_field[label]'
=>
$file_field
,
'_add_new_field[field_name]'
=>
$file_field
,
'_add_new_field[type]'
=>
'file'
,
'_add_new_field[widget_type]'
=>
'file_generic'
,
);
$this
->
drupalPost
(
'admin/structure/types/manage/'
.
$bundle_name
.
'/fields'
,
$edit
,
t
(
'Save'
));
// Set the RDF mapping for the new field.
$rdf_mapping
=
rdf_mapping_load
(
'node'
,
$bundle_name
);
$rdf_mapping
+=
array
(
'field_'
.
$file_field
=>
array
(
'predicates'
=>
array
(
'rdfs:seeAlso'
),
'type'
=>
'rel'
));
$rdf_mapping_save
=
array
(
'mapping'
=>
$rdf_mapping
,
'type'
=>
'node'
,
'bundle'
=>
$bundle_name
);
rdf_mapping_save
(
$rdf_mapping_save
);
// Get the test file that simpletest provides.
$file
=
current
(
$this
->
drupalGetTestFiles
(
'text'
));
// Prepare image variables.
$image_field
=
"field_image"
;
// Get the test image that simpletest provides.
$image
=
current
(
$this
->
drupalGetTestFiles
(
'image'
));
// Create an array for drupalPost with the field names as the keys and
// the uris for the test files as the values.
$edit
=
array
(
"files[field_"
.
$file_field
.
"_"
.
$langcode
.
"_0]"
=>
drupal_realpath
(
$file
->
uri
),
"files["
.
$image_field
.
"_"
.
$langcode
.
"_0]"
=>
drupal_realpath
(
$image
->
uri
));
// Create node and save, then edit node to upload files.
$node
=
$this
->
drupalCreateNode
(
array
(
'type'
=>
'article'
,
'promote'
=>
1
));
$this
->
drupalPost
(
'node/'
.
$node
->
nid
.
'/edit'
,
$edit
,
t
(
'Save'
));
// Get filenames and nid for comparison with HTML output.
$file_filename
=
$file
->
filename
;
$image_filename
=
$image
->
filename
;
$nid
=
$node
->
nid
;
// Navigate to front page, where node is displayed in teaser form.
$this
->
drupalGet
(
'node'
);
// We only check to make sure that the resource attribute contains '.txt'
// instead of the full file name because the filename is altered on upload.
$file_rel
=
$this
->
xpath
(
"//div[contains(@about, 'node/
$nid
')]//div[contains(@rel, 'rdfs:seeAlso') and contains(@resource, '.txt')]"
);
$this
->
assertTrue
(
!
empty
(
$file_rel
),
t
(
'Attribute \'rel\' set on file field. Attribute \'resource\' is also set.'
));
$image_rel
=
$this
->
xpath
(
"//div[contains(@about, 'node/
$nid
')]//div[contains(@rel, 'rdfs:seeAlso') and contains(@resource, '
$image_filename
')]//img[contains(@typeof, 'foaf:Image')]"
);
$this
->
assertTrue
(
!
empty
(
$image_rel
),
t
(
'Attribute \'rel\' set on image field. Attribute \'resource\' is also set.'
));
}
}
class
RdfCrudTestCase
extends
DrupalWebTestCase
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment