function rdf_get_mapping in Drupal 9
Same name and namespace in other branches
- 8 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
19 calls to rdf_get_mapping()
- CommentAttributesTest::setUp in core/
modules/ rdf/ tests/ src/ Functional/ CommentAttributesTest.php - DateTimeFieldRdfaTest::setUp in core/
modules/ rdf/ tests/ src/ Kernel/ Field/ DateTimeFieldRdfaTest.php - Set the default field storage backend for fields created during tests.
- EmailFieldRdfaTest::setUp in core/
modules/ rdf/ tests/ src/ Kernel/ Field/ EmailFieldRdfaTest.php - Set the default field storage backend for fields created during tests.
- EntityReferenceRdfaTest::setUp in core/
modules/ rdf/ tests/ src/ Kernel/ Field/ EntityReferenceRdfaTest.php - Set the default field storage backend for fields created during tests.
- EntityViewControllerTest::testFieldItemAttributes in core/
modules/ system/ tests/ src/ Functional/ Entity/ EntityViewControllerTest.php - Tests field item attributes.
File
- core/
modules/ rdf/ rdf.module, line 73 - 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 = RdfMapping::load($entity_type . '.' . $bundle);
// If not found, create a fresh mapping object.
if (!$mapping) {
$mapping = RdfMapping::create([
'targetEntityType' => $entity_type,
'bundle' => $bundle,
]);
}
return $mapping;
}