diff --git a/core/modules/rdf/lib/Drupal/rdf/Tests/GetNamespacesTest.php b/core/modules/rdf/lib/Drupal/rdf/Tests/GetNamespacesTest.php index 4a68e52..a133230 100644 --- a/core/modules/rdf/lib/Drupal/rdf/Tests/GetNamespacesTest.php +++ b/core/modules/rdf/lib/Drupal/rdf/Tests/GetNamespacesTest.php @@ -52,8 +52,8 @@ function testGetRdfNamespaces() { $this->assertTrue(!empty($element), 'Two prefixes can be assigned the same namespace.'); $element = $this->xpath('//html[contains(@prefix, :prefix_binding)]', array( - ':prefix_binding' => 'dc: ', + ':prefix_binding' => 'dc: http://purl.org/dc/terms/', )); - $this->assertTrue(empty($element), 'A prefix with conflicting namespaces is discarded.'); + $this->assertTrue(!empty($element), 'When a prefix has conflicting namespaces, the first declared one is used.'); } } diff --git a/core/modules/rdf/lib/Drupal/rdf/Tests/GetRdfNamespacesTest.php b/core/modules/rdf/lib/Drupal/rdf/Tests/GetRdfNamespacesTest.php index 997e41a..362a416 100644 --- a/core/modules/rdf/lib/Drupal/rdf/Tests/GetRdfNamespacesTest.php +++ b/core/modules/rdf/lib/Drupal/rdf/Tests/GetRdfNamespacesTest.php @@ -39,6 +39,6 @@ function testGetRdfNamespaces() { $this->assertEqual($ns['rdfs'], 'http://www.w3.org/2000/01/rdf-schema#', 'A prefix declared once is included.'); $this->assertEqual($ns['foaf'], 'http://xmlns.com/foaf/0.1/', 'The same prefix declared in several implementations of hook_rdf_namespaces() is valid as long as all the namespaces are the same.'); $this->assertEqual($ns['foaf1'], 'http://xmlns.com/foaf/0.1/', 'Two prefixes can be assigned the same namespace.'); - $this->assertTrue(!isset($ns['dc']), 'A prefix with conflicting namespaces is discarded.'); + $this->assertEqual($ns['dc'], 'http://purl.org/dc/terms/', 'When a prefix has conflicting namespaces, the first declared one is used.'); } } diff --git a/core/modules/rdf/rdf.module b/core/modules/rdf/rdf.module index 72d038e..c72c4cd 100644 --- a/core/modules/rdf/rdf.module +++ b/core/modules/rdf/rdf.module @@ -5,6 +5,7 @@ * Enables semantically enriched output for Drupal sites in the form of RDFa. */ +use Drupal\Component\Utility\NestedArray; use Drupal\Core\Template\Attribute; /** @@ -99,27 +100,14 @@ function rdf_rdf_namespaces() { * implement it. */ function rdf_get_namespaces() { - $rdf_namespaces = module_invoke_all('rdf_namespaces'); - // module_invoke_all() uses array_merge_recursive() which might return nested - // arrays if several modules redefine the same prefix multiple times. We need - // to ensure the array of namespaces is flat and only contains strings as - // URIs. - foreach ($rdf_namespaces as $prefix => $uri) { - if (is_array($uri)) { - if (count(array_unique($uri)) == 1) { - // All namespaces declared for this prefix are the same, merge them all - // into a single namespace. - $rdf_namespaces[$prefix] = $uri[0]; - } - else { - // There are conflicting namespaces for this prefix, do not include - // duplicates in order to avoid asserting any inaccurate RDF - // statements. - unset($rdf_namespaces[$prefix]); - } + $namespaces = array(); + foreach (module_implements('rdf_namespaces') as $module) { + $function = $module . '_rdf_namespaces'; + if (function_exists($function)) { + $namespaces = NestedArray::mergeDeep($function(), $namespaces); } } - return $rdf_namespaces; + return $namespaces; } /** @@ -703,7 +691,7 @@ function rdf_preprocess_username(&$variables) { // (see http://www.w3.org/TR/rdfa-syntax/#rdfa-attributes). // Therefore, merge rather than override so as not to clobber values set by // earlier preprocess functions. - $variables['attributes'] = drupal_array_merge_deep($variables['attributes'], $attributes); + $variables['attributes'] = NestedArray::mergeDeep($variables['attributes'], $attributes); } /**