diff --git a/core/modules/rdf/rdf.module b/core/modules/rdf/rdf.module
index 1beb1a1053f3366837ac909f86e450ee1ebe02d0..35ac8b8a8327b4603aea2e6f5a707ccba71b1650 100644
--- a/core/modules/rdf/rdf.module
+++ b/core/modules/rdf/rdf.module
@@ -247,6 +247,9 @@ function rdf_comment_storage_load($comments) {
*/
function rdf_theme() {
return array(
+ 'rdf_wrapper' => array(
+ 'variables' => array('attributes' => array(), 'content' => NULL),
+ ),
'rdf_metadata' => array(
'variables' => array('metadata' => array()),
),
@@ -440,11 +443,19 @@ function rdf_preprocess_comment(&$variables) {
// Adds RDFa markup for the relation between the comment and its author.
$author_mapping = $mapping->getPreparedFieldMapping('uid');
if (!empty($author_mapping)) {
- $author_attributes = array('rel' => $author_mapping['properties']);
- // Wraps the author variable and the submitted variable which are both
- // available in comment.html.twig.
- $variables['author'] = SafeMarkup::set('' . $variables['author'] . '');
- $variables['submitted'] = SafeMarkup::set('' . $variables['submitted'] . '');
+ $author_attributes = ['rel' => $author_mapping['properties']];
+ // Wraps the 'author' and 'submitted' variables which are both available in
+ // comment.html.twig.
+ $variables['author'] = [
+ '#theme' => 'rdf_wrapper',
+ '#content' => $variables['author'],
+ '#attributes' => $author_attributes,
+ ];
+ $variables['submitted'] = [
+ '#theme' => 'rdf_wrapper',
+ '#content' => $variables['submitted'],
+ '#attributes' => $author_attributes,
+ ];
}
// Adds RDFa markup for the date of the comment.
$created_mapping = $mapping->getPreparedFieldMapping('created');
@@ -457,11 +468,12 @@ function rdf_preprocess_comment(&$variables) {
'#theme' => 'rdf_metadata',
'#metadata' => array($date_attributes),
);
- $created_metadata_markup = drupal_render($rdf_metadata);
- // Appends the markup to the created variable and the submitted variable
- // which are both available in comment.html.twig.
- $variables['created'] = SafeMarkup::set(SafeMarkup::escape($variables['created']) . $created_metadata_markup);
- $variables['submitted'] = SafeMarkup::set($variables['submitted'] . $created_metadata_markup);
+ // Ensure the original variable is represented as a render array.
+ $created = !is_array($variables['created']) ? ['#markup' => $variables['created']] : $variables['created'];
+ $submitted = !is_array($variables['submitted']) ? ['#markup' => $variables['submitted']] : $variables['submitted'];
+ // Make render array and RDF metadata available in comment.html.twig.
+ $variables['created'] = [$created, $rdf_metadata];
+ $variables['submitted'] = [$submitted, $rdf_metadata];
}
$title_mapping = $mapping->getPreparedFieldMapping('subject');
if (!empty($title_mapping)) {
diff --git a/core/modules/rdf/src/Tests/CommentAttributesTest.php b/core/modules/rdf/src/Tests/CommentAttributesTest.php
index f7ad33a228b2a1b0b6171a8544f5bd3bce4f3c5e..8d3beb756455e2a375e88d8fa25bdc2938754402 100644
--- a/core/modules/rdf/src/Tests/CommentAttributesTest.php
+++ b/core/modules/rdf/src/Tests/CommentAttributesTest.php
@@ -144,6 +144,24 @@ public function testNumberOfCommentsRdfaMarkup() {
$this->assertTrue($graph->hasProperty($this->nodeUri, 'http://rdfs.org/sioc/ns#num_replies', $expected_value), 'Number of comments found in RDF output of full node view mode (sioc:num_replies).');
}
+ /**
+ * Tests comment author link markup has not been broken by RDF.
+ */
+ public function testCommentRdfAuthorMarkup() {
+ // Post a comment as a registered user.
+ $this->saveComment($this->node->id(), $this->webUser->id());
+
+ // Give the user access to view user profiles so the profile link shows up.
+ user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, ['access user profiles']);
+ $this->drupalLogin($this->webUser);
+
+ // Ensure that the author link still works properly after the author output
+ // is modified by the RDF module.
+ $this->drupalGet('node/' . $this->node->id());
+ $this->assertLink($this->webUser->getUsername());
+ $this->assertLinkByHref('user/' . $this->webUser->id());
+ }
+
/**
* Tests if RDFa markup for meta information is present in comments.
*
diff --git a/core/modules/rdf/templates/rdf-wrapper.html.twig b/core/modules/rdf/templates/rdf-wrapper.html.twig
new file mode 100644
index 0000000000000000000000000000000000000000..cfdb31e21a2484f6aed2428101bbe8a5a47f6176
--- /dev/null
+++ b/core/modules/rdf/templates/rdf-wrapper.html.twig
@@ -0,0 +1,13 @@
+{#
+/**
+ * @file
+ * Default theme implementation for wrapping content with RDF attributes.
+ *
+ * Available variables:
+ * - content: The content being wrapped with RDF attributes.
+ * - attributes: HTML attributes, including RDF attributes for wrapper element.
+ *
+ * @ingroup themeable
+ */
+#}
+{{ content }}