Skip to content
Snippets Groups Projects
Commit 2162877c authored by Angie Byron's avatar Angie Byron
Browse files

#642122 by scor and Stefan Freudenberg: Allow for RDFa datatype attribute...

#642122 by scor and Stefan Freudenberg: Allow for RDFa datatype attribute without callback function.
parent 811be8f7
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -236,14 +236,13 @@ function rdf_rdfa_attributes($mapping, $data = NULL) {
// literal text.
case 'property':
$attributes['property'] = $mapping['predicates'];
if (isset($mapping['callback']) && isset($data)) {
// Convert $data to a specific format as per the callback function.
if (isset($data) && isset($mapping['callback']) && function_exists($mapping['callback'])) {
$callback = $mapping['callback'];
if (function_exists($callback)) {
$attributes['content'] = $callback($data);
}
if (isset($mapping['datatype'])) {
$attributes['datatype'] = $mapping['datatype'];
}
$attributes['content'] = $callback($data);
}
if (isset($mapping['datatype'])) {
$attributes['datatype'] = $mapping['datatype'];
}
break;
}
......
......@@ -35,7 +35,7 @@ class RdfMappingHookTestCase extends DrupalWebTestCase {
'datatype' => 'xsd:dateTime',
'callback' => 'date_iso8601',
), t('Mapping for created is dc:created with datatype xsd:dateTime and callback date_iso8601.'));
$this->assertIdentical($mapping['uid'], array('predicates' => array('sioc:has_creator', 'dc:creator')), t('Mapping for uid is sioc:has_creator and dc:creator.'));
$this->assertIdentical($mapping['uid'], array('predicates' => array('sioc:has_creator', 'dc:creator'), 'type' => 'rel'), t('Mapping for uid is sioc:has_creator and dc:creator, and type is rel.'));
$mapping = rdf_mapping_load('test_entity', 'test_bundle_no_mapping');
$this->assertEqual($mapping, array(), t('Empty array returned when an entity type, bundle pair has no mapping.'));
......@@ -60,19 +60,60 @@ class RdfMarkupTestCase extends DrupalWebTestCase {
* Test rdf_rdfa_attributes().
*/
function testDrupalRdfaAtributes() {
// Same value as the one in the HTML tag (no callback function).
$expected_attributes = array(
'property' => array('dc:title'),
);
$mapping = rdf_mapping_load('test_entity', 'test_bundle');
$attributes = rdf_rdfa_attributes($mapping['title']);
ksort($expected_attributes);
ksort($attributes);
$this->assertEqual($expected_attributes, $attributes);
// Value different from the one in the HTML tag (callback function).
$date = 1252750327;
$isoDate = date('c', $date);
$expected_type = 'xsd:dateTime';
$expected_property = array('dc:created');
$expected_value = $isoDate;
$expected_attributes = array(
'datatype' => 'xsd:dateTime',
'property' => array('dc:created'),
'content' => $isoDate,
);
$mapping = rdf_mapping_load('test_entity', 'test_bundle');
$attributes = rdf_rdfa_attributes($mapping['created'], $date);
$this->assertEqual($expected_type, $attributes['datatype']);
$this->assertEqual($expected_property, $attributes['property']);
$this->assertEqual($expected_value, $attributes['content']);
ksort($expected_attributes);
ksort($attributes);
$this->assertEqual($expected_attributes, $attributes);
// Same value as the one in the HTML tag with datatype.
$expected_attributes = array(
'datatype' => 'foo:bar1type',
'property' => array('foo:bar1'),
);
$mapping = rdf_mapping_load('test_entity', 'test_bundle');
$attributes = rdf_rdfa_attributes($mapping['foobar1']);
ksort($expected_attributes);
ksort($attributes);
$this->assertEqual($expected_attributes, $attributes);
// ObjectProperty mapping (rel).
$expected_attributes = array(
'rel' => array('sioc:has_creator', 'dc:creator'),
);
$mapping = rdf_mapping_load('test_entity', 'test_bundle');
$attributes = rdf_rdfa_attributes($mapping['foobar_objproperty1']);
ksort($expected_attributes);
ksort($attributes);
$this->assertEqual($expected_attributes, $attributes);
// Inverse ObjectProperty mapping (rev).
$expected_attributes = array(
'rev' => array('sioc:reply_of'),
);
$mapping = rdf_mapping_load('test_entity', 'test_bundle');
$attributes = rdf_rdfa_attributes($mapping['foobar_objproperty2']);
ksort($expected_attributes);
ksort($attributes);
$this->assertEqual($expected_attributes, $attributes);
}
}
......
......@@ -26,10 +26,23 @@ function rdf_test_rdf_mapping() {
),
'uid' => array(
'predicates' => array('sioc:has_creator', 'dc:creator'),
'type' => 'rel',
),
'foobar' => array(
'predicates' => array('foo:bar'),
),
'foobar1' => array(
'datatype' => 'foo:bar1type',
'predicates' => array('foo:bar1'),
),
'foobar_objproperty1' => array(
'predicates' => array('sioc:has_creator', 'dc:creator'),
'type' => 'rel',
),
'foobar_objproperty2' => array(
'predicates' => array('sioc:reply_of'),
'type' => 'rev',
),
),
),
array(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment