function rdf_rdfa_attributes

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.

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

Return value

RDFa attributes suitable for Drupal\Core\Template\Attribute.

See also

theme_rdf_template_variable_wrapper()

Related topics

5 calls to rdf_rdfa_attributes()
RdfaMarkupTest::testDrupalRdfaAttributes in drupal/core/modules/rdf/lib/Drupal/rdf/Tests/RdfaMarkupTest.php
Tests rdf_rdfa_attributes().
rdf_comment_load in drupal/core/modules/rdf/rdf.module
Implements hook_comment_load().
rdf_preprocess_field in drupal/core/modules/rdf/rdf.module
Implements hook_preprocess_HOOK() for field.tpl.php.
rdf_preprocess_node in drupal/core/modules/rdf/rdf.module
Implements hook_preprocess_HOOK() for node.html.twig.
tracker_page in drupal/core/modules/tracker/tracker.pages.inc
Page callback: Generates a page of tracked nodes for the site.

File

drupal/core/modules/rdf/rdf.module, line 304
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'])) {
        $callback = $mapping['callback'];
        $attributes['content'] = $callback($data);
      }
      if (isset($mapping['datatype'])) {
        $attributes['datatype'] = $mapping['datatype'];
      }
      break;
  }
  return $attributes;
}