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()
parent
e415ad43eb
commit
d6002691b2
|
|
@ -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)) {
|
||||
|
|
|
|||
|
|
@ -144,6 +144,24 @@ class CommentAttributesTest extends CommentTestBase {
|
|||
$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.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
Loading…
Reference in New Issue