Skip to content
Snippets Groups Projects
Commit 6c4cdee9 authored by catch's avatar catch
Browse files

Issue #2141929 by andypost, clemens.tolboom, mgifford: Comment link or form is...

Issue #2141929 by andypost, clemens.tolboom, mgifford: Comment link or form is added to print view mode.
parent a1c6a9d7
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -436,6 +436,13 @@ function comment_entity_view(EntityInterface $entity, EntityViewDisplayInterface
// http://drupal.org/node/1901110
return;
}
if ($view_mode == 'search_index' || $view_mode == 'search_result' || $view_mode == 'print') {
// Do not add any links if the entity displayed for:
// - search indexing.
// - constructing a search result excerpt.
// - print.
return;
}
$fields = \Drupal::service('comment.manager')->getFields('node');
foreach ($fields as $field_name => $detail) {
// Skip fields that entity does not have.
......@@ -514,11 +521,9 @@ function comment_entity_view(EntityInterface $entity, EntityViewDisplayInterface
}
}
}
elseif ($view_mode != 'search_index' && $view_mode != 'search_result') {
else {
// Entity in other view modes: add a "post comment" link if the user is
// allowed to post comments and if this entity is allowing new comments.
// But we don't want this link if we're building the entity for search
// indexing or constructing a search result excerpt.
if ($commenting_status == COMMENT_OPEN) {
$comment_form_location = $instance->getSetting('form_location');
if (user_access('post comments')) {
......
......@@ -143,8 +143,8 @@ public function viewElements(FieldItemListInterface $items) {
}
// Append comment form if the comments are open and the form is set to
// display below the entity.
if ($status == COMMENT_OPEN && $comment_settings['form_location'] == COMMENT_FORM_BELOW) {
// display below the entity. Do not show the form for the print view mode.
if ($status == COMMENT_OPEN && $comment_settings['form_location'] == COMMENT_FORM_BELOW && $this->viewMode != 'print') {
// Only show the add comment form if the user has permission.
if ($this->currentUser->hasPermission('post comments')) {
// All users in the "anonymous" role can use the same form: it is fine
......
<?php
/**
* @file
* Contains \Drupal\comment\Tests\CommentBookTest.
*/
namespace Drupal\comment\Tests;
use Drupal\comment\CommentInterface;
use Drupal\simpletest\WebTestBase;
/**
* Tests the comment module integration for book module.
*/
class CommentBookTest extends WebTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('book', 'comment');
public static function getInfo() {
return array(
'name' => 'Book commenting',
'description' => 'Test visibility of comments on book pages.',
'group' => 'Book',
);
}
function setUp() {
parent::setUp();
// Create comment field on book.
\Drupal::service('comment.manager')->addDefaultField('node', 'book');
}
/**
* Tests comments in book export.
*/
public function testBookCommentPrint() {
$book_node = entity_create('node', array(
'type' => 'book',
'title' => 'Book title',
'body' => 'Book body',
));
$book_node->book['bid'] = 'new';
$book_node->save();
$comment_subject = $this->randomName(8);
$comment_body = $this->randomName(8);
$comment = entity_create('comment', array(
'subject' => $comment_subject,
'comment_body' => $comment_body,
'entity_id' => $book_node->id(),
'entity_type' => 'node',
'field_name' => 'comment',
'status' => CommentInterface::PUBLISHED,
));
$comment->save();
$commenting_user = $this->drupalCreateUser(array('access printer-friendly version', 'access comments', 'post comments'));
$this->drupalLogin($commenting_user);
$this->drupalGet('node/' . $book_node->id());
$this->assertText($comment_subject, 'Comment subject found');
$this->assertText($comment_body, 'Comment body found');
$this->assertText(t('Add new comment'), 'Comment form found');
$this->assertField('subject', 'Comment form subject found');
$this->drupalGet('book/export/html/' . $book_node->id());
$this->assertText(t('Comments'), 'Comment thread found');
$this->assertText($comment_subject, 'Comment subject found');
$this->assertText($comment_body, 'Comment body found');
$this->assertNoText(t('Add new comment'), 'Comment form not found');
$this->assertNoField('subject', 'Comment form subject not found');
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment