summaryrefslogtreecommitdiff
path: root/modules/comment
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2010-02-07 09:11:28 +0000
committerDries Buytaert <dries@buytaert.net>2010-02-07 09:11:28 +0000
commit2893abcc62e5e5bc4ab0794e3267c5fef7619d10 (patch)
treeb522e8c0f3c3ef98d7baae5771b560c5b2e44fcf /modules/comment
parent32fc5ac8359b1db9533708e212f29369ff18543c (diff)
downloadbrdo-2893abcc62e5e5bc4ab0794e3267c5fef7619d10.tar.gz
brdo-2893abcc62e5e5bc4ab0794e3267c5fef7619d10.tar.bz2
- Patch #652246 by effulgentsia, scor: optimize theme('field') and use it for comment body.
Diffstat (limited to 'modules/comment')
-rw-r--r--modules/comment/comment.module31
-rw-r--r--modules/comment/comment.test28
2 files changed, 17 insertions, 42 deletions
diff --git a/modules/comment/comment.module b/modules/comment/comment.module
index 556c234c2..ca5958ace 100644
--- a/modules/comment/comment.module
+++ b/modules/comment/comment.module
@@ -938,33 +938,6 @@ function comment_build_content($comment, $node, $view_mode = 'full') {
entity_prepare_view('comment', array($comment->cid => $comment));
$comment->content += field_attach_view('comment', $comment, $view_mode);
- // Prior to Drupal 7, the comment body was a simple text variable, but with
- // Drupal 7, it has been upgraded to a field. However, using theme('field') to
- // render the comment body results in a noticeable performance degradation for
- // pages with many comments. By unsetting #theme, we avoid the overhead of
- // theme('field') and instead settle for simply rendering the formatted field
- // value that exists as a child element of the 'comment_body' render array,
- // which results in equivalent markup and rendering speed as if the comment
- // body had not been upgraded to a field. Modules that require the comment
- // body to be rendered as a full field (and are willing to accept the
- // corresponding performance impact) can restore #theme to 'field' within a
- // hook_comment_view() or hook_comment_view_alter() implementation.
- // @todo Bypassing theme('field') is not ideal, because:
- // - The field label is not displayed, even if its setting is to be
- // displayed.
- // - hook_preprocess_field() functions do not run, and therefore, attributes
- // added in those functions (for example, for RDF) are not output.
- // - The HTML markup that's within field.tpl.php is not output, so theme
- // developers must use different CSS rules for the comment body than for
- // all other fields.
- // The goal is for theme('field') to be sufficiently optimized prior to
- // Drupal 7 release, so that this code can be removed, and the comment body
- // can be rendered just like all other fields. Otherwise, another solution
- // to the above problems will be needed. @see http://drupal.org/node/659788.
- if (isset($comment->content['comment_body']['#theme']) && ($comment->content['comment_body']['#theme'] === 'field')) {
- unset($comment->content['comment_body']['#theme']);
- }
-
if (empty($comment->in_preview)) {
$comment->content['links']['comment'] = array(
'#theme' => 'links__comment',
@@ -2566,7 +2539,7 @@ function comment_rdf_mapping() {
'type' => 'comment',
'bundle' => RDF_DEFAULT_BUNDLE,
'mapping' => array(
- 'rdftype' => array('sioc:Post'),
+ 'rdftype' => array('sioc:Post', 'sioct:Comment'),
'title' => array(
'predicates' => array('dc:title'),
),
@@ -2580,7 +2553,7 @@ function comment_rdf_mapping() {
'datatype' => 'xsd:dateTime',
'callback' => 'date_iso8601',
),
- 'body' => array(
+ 'comment_body' => array(
'predicates' => array('content:encoded'),
),
'pid' => array(
diff --git a/modules/comment/comment.test b/modules/comment/comment.test
index 889538036..6237ea5b3 100644
--- a/modules/comment/comment.test
+++ b/modules/comment/comment.test
@@ -1149,10 +1149,10 @@ class CommentRdfaTestCase extends CommentHelperCase {
// Tests comment #2 as anonymous user.
$this->_testBasicCommentRdfaMarkup($comment2, $anonymous_user);
// Tests the RDFa markup for the homepage (specific to anonymous comments).
- $comment_homepage = $this->xpath("//div[@typeof='sioc:Post']//span[@rel='sioc:has_creator']/a[contains(@class, 'username') and @typeof='sioc:User' and @property='foaf:name' and @href='http://example.org/' and contains(@rel, 'foaf:page')]");
+ $comment_homepage = $this->xpath("//div[contains(@class, 'comment') and contains(@typeof, 'sioct:Comment')]//span[@rel='sioc:has_creator']/a[contains(@class, 'username') and @typeof='sioc:User' and @property='foaf:name' and @href='http://example.org/' and contains(@rel, 'foaf:page')]");
$this->assertTrue(!empty($comment_homepage), t('RDFa markup for the homepage of anonymous user found.'));
// There should be no about attribute on anonymous comments.
- $comment_homepage = $this->xpath("//div[@typeof='sioc:Post']//span[@rel='sioc:has_creator']/a[@about]");
+ $comment_homepage = $this->xpath("//div[contains(@class, 'comment') and contains(@typeof, 'sioct:Comment')]//span[@rel='sioc:has_creator']/a[@about]");
$this->assertTrue(empty($comment_homepage), t('No about attribute is present on anonymous user comment.'));
// Tests comment #2 as logged in user.
@@ -1160,10 +1160,10 @@ class CommentRdfaTestCase extends CommentHelperCase {
$this->drupalGet('node/' . $this->node2->nid);
$this->_testBasicCommentRdfaMarkup($comment2, $anonymous_user);
// Tests the RDFa markup for the homepage (specific to anonymous comments).
- $comment_homepage = $this->xpath("//div[@typeof='sioc:Post']//span[@rel='sioc:has_creator']/a[contains(@class, 'username') and @typeof='sioc:User' and @property='foaf:name' and @href='http://example.org/' and contains(@rel, 'foaf:page')]");
+ $comment_homepage = $this->xpath("//div[contains(@class, 'comment') and contains(@typeof, 'sioct:Comment')]//span[@rel='sioc:has_creator']/a[contains(@class, 'username') and @typeof='sioc:User' and @property='foaf:name' and @href='http://example.org/' and contains(@rel, 'foaf:page')]");
$this->assertTrue(!empty($comment_homepage), t('RDFa markup for the homepage of anonymous user found.'));
// There should be no about attribute on anonymous comments.
- $comment_homepage = $this->xpath("//div[@typeof='sioc:Post']//span[@rel='sioc:has_creator']/a[@about]");
+ $comment_homepage = $this->xpath("//div[contains(@class, 'comment') and contains(@typeof, 'sioct:Comment')]//span[@rel='sioc:has_creator']/a[@about]");
$this->assertTrue(empty($comment_homepage), t('No about attribute is present on anonymous user comment.'));
}
@@ -1174,20 +1174,22 @@ class CommentRdfaTestCase extends CommentHelperCase {
*
* @param $comment
* Comment object.
- * @param $acount
+ * @param $account
* An array containing information about an anonymous user.
*/
function _testBasicCommentRdfaMarkup($comment, $account = array()) {
- $comment_container = $this->xpath("//div[contains(@class, 'comment') and @typeof='sioc:Post']");
- $this->assertTrue(!empty($comment_container));
- $comment_title = $this->xpath("//div[@typeof='sioc:Post']//h3[@property='dc:title']");
- $this->assertEqual((string)$comment_title[0]->a, $comment->subject);
- $comment_date = $this->xpath("//div[@typeof='sioc:Post']//*[contains(@property, 'dc:date') and contains(@property, 'dc:created')]");
- $this->assertTrue(!empty($comment_date));
+ $comment_container = $this->xpath("//div[contains(@class, 'comment') and contains(@typeof, 'sioct:Comment')]");
+ $this->assertTrue(!empty($comment_container), t('Comment RDF type for comment found.'));
+ $comment_title = $this->xpath("//div[contains(@class, 'comment') and contains(@typeof, 'sioct:Comment')]//h3[@property='dc:title']");
+ $this->assertEqual((string)$comment_title[0]->a, $comment->subject, t('RDFa markup for the comment title found.'));
+ $comment_date = $this->xpath("//div[contains(@class, 'comment') and contains(@typeof, 'sioct:Comment')]//*[contains(@property, 'dc:date') and contains(@property, 'dc:created')]");
+ $this->assertTrue(!empty($comment_date), t('RDFa markup for the date of the comment found.'));
// The author tag can be either a or span
- $comment_author = $this->xpath("//div[@typeof='sioc:Post']//span[@rel='sioc:has_creator']/*[contains(@class, 'username') and @typeof='sioc:User' and @property='foaf:name']");
+ $comment_author = $this->xpath("//div[contains(@class, 'comment') and contains(@typeof, 'sioct:Comment')]//span[@rel='sioc:has_creator']/*[contains(@class, 'username') and @typeof='sioc:User' and @property='foaf:name']");
$name = empty($account['name']) ? $this->web_user->name : $account['name'] . ' (not verified)';
- $this->assertEqual((string)$comment_author[0], $name);
+ $this->assertEqual((string)$comment_author[0], $name, t('RDFa markup for the comment author found.'));
+ $comment_body = $this->xpath("//div[contains(@class, 'comment') and contains(@typeof, 'sioct:Comment')]//div[@class='content']//div[contains(@class, 'comment-body')]//div[@property='content:encoded']");
+ $this->assertEqual((string)$comment_body[0]->p, $comment->comment, t('RDFa markup for the comment body found.'));
}
}