function 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/ 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.
 - FieldRdfaDatatypeCallbackTest::setUp in core/
modules/ rdf/ tests/ src/ Kernel/ Field/ FieldRdfaDatatypeCallbackTest.php  - Set the default field storage backend for fields created during tests.
 
File
- 
              core/
modules/ rdf/ rdf.module, line 74  
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;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.