summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorxjm2015-08-15 18:22:43 (GMT)
committerxjm2015-08-15 18:22:43 (GMT)
commitd6002691b239842470690a318f6c7cacce9dd815 (patch)
treec446171daf12dc9925d8184c1ec29e1935a95461
parente415ad43eb25e9da8a8ca7fa39682b593c04de24 (diff)
Issue #2501697 by ZenDoodles, leslieg, Les Lim, pfrenssen, joelpittet, hestenet, YesCT, scor, Cottser, xjm, lauriii, dsnopek, alexpott, akalata, Wim Leers, acouch, kgoel: Remove SafeMarkup::set in rdf_preprocess_comment()
-rw-r--r--core/modules/rdf/rdf.module32
-rw-r--r--core/modules/rdf/src/Tests/CommentAttributesTest.php18
-rw-r--r--core/modules/rdf/templates/rdf-wrapper.html.twig13
3 files changed, 53 insertions, 10 deletions
diff --git a/core/modules/rdf/rdf.module b/core/modules/rdf/rdf.module
index 1beb1a1..35ac8b8 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('<span ' . new Attribute($author_attributes) . '>' . $variables['author'] . '</span>');
- $variables['submitted'] = SafeMarkup::set('<span ' . new Attribute($author_attributes) . '>' . $variables['submitted'] . '</span>');
+ $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 f7ad33a..8d3beb7 100644
--- a/core/modules/rdf/src/Tests/CommentAttributesTest.php
+++ b/core/modules/rdf/src/Tests/CommentAttributesTest.php
@@ -145,6 +145,24 @@ class CommentAttributesTest extends CommentTestBase {
}
/**
+ * 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.
*
* Tests presence of RDFa markup for the title, date and author and homepage
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 0000000..cfdb31e
--- /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
+ */
+#}
+<span{{ attributes }}>{{ content }}</span>