You are here

function rdf_rdfa_attributes in Drupal 7

Same name and namespace in other branches
  1. 8 core/modules/rdf/rdf.module \rdf_rdfa_attributes()
  2. 9 core/modules/rdf/rdf.module \rdf_rdfa_attributes()

Builds an array of RDFa attributes for a given mapping. This array will typically be passed through drupal_attributes() 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. For more information, see theme_rdf_template_variable_wrapper().

Parameters

$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: A value that needs to be converted by the provided callback function.

Return value

An array containing RDFa attributes suitable for drupal_attributes().

Related topics

5 calls to rdf_rdfa_attributes()
RdfRdfaMarkupTestCase::testDrupalRdfaAttributes in modules/rdf/rdf.test
Test rdf_rdfa_attributes().
rdf_comment_load in modules/rdf/rdf.module
Implements hook_comment_load().
rdf_preprocess_field in modules/rdf/rdf.module
Implements MODULE_preprocess_HOOK().
rdf_preprocess_node in modules/rdf/rdf.module
Implements MODULE_preprocess_HOOK().
tracker_page in modules/tracker/tracker.pages.inc
Page callback: prints a listing of active nodes on the site.

File

modules/rdf/rdf.module, line 307
Enables semantically enriched output for Drupal sites in the form of RDFa.

Code

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']) && function_exists($mapping['callback'])) {
        $callback = $mapping['callback'];
        $attributes['content'] = $callback($data);
      }
      if (isset($mapping['datatype'])) {
        $attributes['datatype'] = $mapping['datatype'];
      }
      break;
  }
  return $attributes;
}