function rdf_get_mapping in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/rdf/rdf.module \rdf_get_mapping()
Returns the RDF mapping object associated with a bundle.
The function reads the rdf_mapping object from the current configuration, or returns a ready-to-use empty one if no configuration entry exists yet for this bundle. This streamlines the manipulation of mapping objects by always returning a consistent object that reflects the current state of the configuration.
Example usage: -Map the 'article' bundle to 'sioc:Post' and the 'title' field to 'dc:title'.
rdf_get_mapping('node', 'article')
->setBundleMapping(array(
'types' => array(
'sioc:Post',
),
))
->setFieldMapping('title', array(
'properties' => array(
'dc:title',
),
))
->save();
Parameters
string $entity_type: The entity type.
string $bundle: The bundle.
Return value
\Drupal\rdf\Entity\RdfMapping The RdfMapping object.
Related topics
18 calls to rdf_get_mapping()
- CommentAttributesTest::setUp in core/
modules/ rdf/ src/ Tests/ CommentAttributesTest.php - Sets up a Drupal site for running functional and integration tests.
- DateTimeFieldRdfaTest::setUp in core/
modules/ rdf/ src/ Tests/ Field/ DateTimeFieldRdfaTest.php - Set the default field storage backend for fields created during tests.
- EmailFieldRdfaTest::setUp in core/
modules/ rdf/ src/ Tests/ Field/ EmailFieldRdfaTest.php - Set the default field storage backend for fields created during tests.
- EntityReferenceRdfaTest::setUp in core/
modules/ rdf/ src/ Tests/ Field/ EntityReferenceRdfaTest.php - Set the default field storage backend for fields created during tests.
- EntityViewControllerTest::testFieldItemAttributes in core/
modules/ system/ src/ Tests/ Entity/ EntityViewControllerTest.php - Tests field item attributes.
File
- core/
modules/ rdf/ rdf.module, line 70 - Enables semantically enriched output for Drupal sites in the form of RDFa.
Code
function rdf_get_mapping($entity_type, $bundle) {
// Try loading the mapping from configuration.
$mapping = entity_load('rdf_mapping', $entity_type . '.' . $bundle);
// If not found, create a fresh mapping object.
if (!$mapping) {
$mapping = entity_create('rdf_mapping', array(
'targetEntityType' => $entity_type,
'bundle' => $bundle,
));
}
return $mapping;
}