You are here

function rdf_get_namespaces in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/rdf/rdf.module \rdf_get_namespaces()
  2. 7 modules/rdf/rdf.module \rdf_get_namespaces()
  3. 9 core/modules/rdf/rdf.module \rdf_get_namespaces()

Retrieves RDF namespaces.

Invokes hook_rdf_namespaces() and collects RDF namespaces from modules that implement it.

Related topics

3 calls to rdf_get_namespaces()
GetRdfNamespacesTest::testGetRdfNamespaces in core/modules/rdf/tests/src/Functional/GetRdfNamespacesTest.php
Tests getting RDF namespaces.
rdf_preprocess_html in core/modules/rdf/rdf.module
Implements hook_preprocess_HOOK() for HTML document templates.
RssFields::render in core/modules/views/src/Plugin/views/row/RssFields.php
1 string reference to 'rdf_get_namespaces'
RssFields::render in core/modules/views/src/Plugin/views/row/RssFields.php

File

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

Code

function rdf_get_namespaces() {
  $namespaces = [];

  // In order to resolve duplicate namespaces by using the earliest defined
  // namespace, do not use \Drupal::moduleHandler()->invokeAll().
  \Drupal::moduleHandler()
    ->invokeAllWith('rdf_namespaces', function (callable $hook, string $module) use (&$namespaces) {
    $namespacesFromHook = $hook();
    foreach ($namespacesFromHook as $prefix => $namespace) {
      if (array_key_exists($prefix, $namespaces) && $namespace !== $namespaces[$prefix]) {
        throw new Exception("Tried to map '{$prefix}' to '{$namespace}', but '{$prefix}' is already mapped to '{$namespaces[$prefix]}'.");
      }
      else {
        $namespaces[$prefix] = $namespace;
      }
    }
  });
  return $namespaces;
}