Builds an array of RDFa attributes for a given mapping.
This array will typically be passed through Drupal\Core\Template\Attribute to create the attributes variables that are available to template files. These include $attributes, $title_attributes, $content_attributes and the field-specific $item_attributes variables.
$mapping: An array containing a mandatory 'predicates' key and optional 'datatype', 'callback' and 'type' keys. For example:
array(
'predicates' => array('dc:created'),
'datatype' => 'xsd:dateTime',
'callback' => 'date_iso8601',
),
);
$data: (optional) A value that needs to be converted by the provided callback function.
RDFa attributes suitable for Drupal\Core\Template\Attribute.
theme_rdf_template_variable_wrapper()
function rdf_rdfa_attributes($mapping, $data = NULL) {
// The type of mapping defaults to 'property'.
$type = isset($mapping['type']) ? $mapping['type'] : 'property';
switch ($type) {
// The mapping expresses the relationship between two resources.
case 'rel':
case 'rev':
$attributes[$type] = $mapping['predicates'];
break;
// The mapping expresses the relationship between a resource and some
// literal text.
case 'property':
$attributes['property'] = $mapping['predicates'];
// Convert $data to a specific format as per the callback function.
if (isset($data) && isset($mapping['callback'])) {
$callback = $mapping['callback'];
$attributes['content'] = $callback($data);
}
if (isset($mapping['datatype'])) {
$attributes['datatype'] = $mapping['datatype'];
}
break;
}
return $attributes;
}