You are here

function rdf_get_mapping in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/rdf/rdf.module \rdf_get_mapping()
  2. 9 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')
  'types' => array(
  ->setFieldMapping('title', array(
  'properties' => array(


string $entity_type: The entity type.

string $bundle: The bundle.

Return value

\Drupal\rdf\Entity\RdfMapping The RdfMapping object.

Related topics

28 calls to rdf_get_mapping()
CommentAttributesTest::setUp in core/modules/rdf/tests/src/Functional/CommentAttributesTest.php
CrudTest::testBundleMapping in core/modules/rdf/tests/src/Kernel/CrudTest.php
Tests the handling of bundle mappings.
CrudTest::testFieldMapping in core/modules/rdf/tests/src/Kernel/CrudTest.php
Tests the handling of field mappings.
CrudTest::testMappingCreation in core/modules/rdf/tests/src/Kernel/CrudTest.php
Tests creation of RDF mapping.
DateTimeFieldRdfaTest::setUp in core/modules/rdf/tests/src/Kernel/Field/DateTimeFieldRdfaTest.php

... See full list


core/modules/rdf/rdf.module, line 73
Enables semantically enriched output for Drupal sites in the form of RDFa.


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;