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:
1 2 3 4 5 6 7 8 9 10 | 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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | 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 ; } |
Please login to continue.