By mlncn on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.x
Introduced in version:
Issue links:
Description:
- Datatype callbacks are used to convert a field value to a specific format for machine processing. We accept arguments to this callback in addition to the value. For instance, instead of hard-coding UserComments UserInteraction into RDF module's Schema.org Data Converter callback, we pass it in as an argument with the key 'interaction_type'.
- You may use any of the UserInteraction types as the 'interaction_type' argument to the datatype_callback callable method or function 'Drupal\rdf\SchemaOrgDataConverter::interactionCount'.
In Drupal 7 this was defined in hook_rdf_mapping(). In Drupal 8, this goes in the YAML for a content type. For instance, a created at field and a comment count:
Before
/**
* Implements hook_rdf_mapping().
*/
function node_rdf_mapping() {
return array(
array(
// ...
'created' => array(
'predicates' => array('dc:date', 'dc:created'),
'datatype' => 'xsd:dateTime',
'callback' => 'date_iso8601',
),
// ...
'comment_count' => array(
'predicates' => array('sioc:num_replies'),
'datatype' => 'xsd:integer',
),
// ...
),
),
);
}
After
created:
properties:
- 'schema:dateCreated'
datatype_callback:
callable: 'date_iso8601'
and
comment_count:
properties:
- 'schema:interactionCount'
datatype_callback:
callable: 'Drupal\rdf\SchemaOrgDataConverter::interactionCount'
arguments:
interaction_type: 'UserComments'
Impacts:
Module developers