By linclark on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.x
Issue links:
Description:
In Drupal 7, the RDF mapping API used a nested array to store a bundle's mappings. In Drupal 8, these mappings are stored using an RdfMapping configurable object.
Saving
Saving in Drupal 7:
<?php
$mapping = array(
'type' => 'node',
'bundle' => 'article',
'mapping' => array(
'rdftype' => array('sioc:Post'),
'title' => array(
'predicates' => array('dc:title'),
),
'created' => array(
'predicates' => array('dc:date', 'dc:created'),
'datatype' => 'xsd:dateTime',
'callback' => 'date_iso8601',
),
'uid' => array(
'predicates' => array('sioc:has_creator'),
'type' => 'rel',
),
),
);
rdf_mapping_save($mapping);
?>
Saving in Drupal 8:
<?php
$mapping = rdf_get_mapping('node', 'article');
// Save the type mapping.
$mapping->setBundleMapping(array(
'types' => array('sioc:Post'),
))
->save();
// Save the title field mapping.
$mapping->setFieldMapping('title', array(
'properties' => array('dc:title'),
))
->save();
// Save the created field mapping.
$mapping->setFieldMapping('created', array(
'properties' => array('dc:date', 'dc:created'),
'datatype' => 'xsd:dateTime',
'datatype_callback' => 'date_iso8601',
))
->save();
// Save the uid field mapping.
$mapping->setFieldMapping('uid', array(
'properties' => array('sioc:has_creator'),
'mapping_type' => 'rel',
))
->save();
?>
Loading
Loading in Drupal 7:
<?php
$mapping = rdf_mapping_load('node', 'article');
/**
Returns the following:
array(
'rdftype' => array('sioc:Post'),
'title' => array(
'predicates' => array('dc:title'),
),
'created' => array(
'predicates' => array('dc:date', 'dc:created'),
'datatype' => 'xsd:dateTime',
'callback' => 'date_iso8601',
),
'uid' => array(
'predicates' => array('sioc:has_creator'),
'type' => 'rel',
),
);
*/
?>
Loading in Drupal 8:
<?php
/**
Loads a mapping for placement in HTML.
*/
$mapping = rdf_get_mapping('node', 'article');
// Loads the prepared type mapping.
$bundle_mapping = $mapping->getPreparedBundleMapping();
/**
Returns the following:
array(
'types' => array('sioc:Post'),
);
*/
// Loads the prepared field mapping.
$title_mapping = $mapping->getPreparedFieldMapping('title');
/**
Returns the following:
array(
'properties' => array('dc:title'),
'datatype' => NULL,
'datatype_callback' => NULL,
'mapping_type' => NULL,
);
*/
?>
<?php
/**
Loads a mapping to be edited.
*/
$mapping = rdf_get_mapping('node', 'article');
// Loads the type mapping config.
$bundle_mapping = $mapping->getBundleMapping();
/**
Returns the following:
array(
'types' => array('sioc:Post'),
);
*/
// Loads the field mapping config.
$title_mapping = $mapping->getFieldMapping('title');
/**
Returns the following:
array(
'properties' => array('dc:title'),
);
*/
?>
Impacts:
Site builders, administrators, editors
Module developers