rdf_rdfa_attributes

rdf_rdfa_attributes($mapping, $data = NULL)

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

array $mapping: An array containing a mandatory 'properties' key and optional 'datatype', 'datatype_callback' and 'type' keys. For example:

    array(
      'properties' => array('schema:interactionCount'),
      'datatype' => 'xsd:integer',
      'datatype_callback' => array(
        'callable' => 'Drupal\rdf\SchemaOrgDataConverter::interactionCount',
        'arguments' => array(
          'interaction_type' => 'UserComments'
        ),
      ),
    );
  

mixed $data: (optional) A value that needs to be converted by the provided callback function.

Return value

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

Related topics

RDF Mapping API
Functions to describe entities and bundles in RDF.

File

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

Code

function rdf_rdfa_attributes($mapping, $data = NULL) {
  $attributes = array();

  // The type of mapping defaults to 'property'.
  $type = isset($mapping['mapping_type']) ? $mapping['mapping_type'] : 'property';

  switch ($type) {
    // The mapping expresses the relationship between two resources.
    case 'rel':
    case 'rev':
      $attributes[$type] = $mapping['properties'];
      break;

      // The mapping expresses the relationship between a resource and some
      // literal text.
    case 'property':
      if (!empty($mapping['properties'])) {
        $attributes['property'] = $mapping['properties'];
        // Convert $data to a specific format as per the callback function.
        if (isset($data) && !empty($mapping['datatype_callback'])) {
          $callback = $mapping['datatype_callback']['callable'];
          $arguments = isset($mapping['datatype_callback']['arguments']) ? $mapping['datatype_callback']['arguments'] : NULL;
          $attributes['content'] = call_user_func($callback, $data, $arguments);
        }
        if (isset($mapping['datatype'])) {
          $attributes['datatype'] = $mapping['datatype'];
        }
        break;
      }
  }

  return $attributes;
}
doc_Drupal
2016-10-29 09:36:34
Comments
Leave a Comment

Please login to continue.