Update to Drupal 8.2.0. For more information, see https://www.drupal.org/project/drupal/releases/8.2.0

This commit is contained in:
Pantheon Automation 2016-10-06 15:16:20 -07:00 committed by Greg Anderson
parent 2f563ab520
commit f1c8716f57
1732 changed files with 52334 additions and 11780 deletions

View file

@ -32,7 +32,7 @@ interface CommentInterface extends ContentEntityInterface, EntityChangedInterfac
/**
* Returns the parent comment entity if this is a reply to a comment.
*
* @return \Drupal\comment\CommentInterface|NULL
* @return \Drupal\comment\CommentInterface|null
* A comment entity of the parent comment or NULL if there is no parent.
*/
public function getParentComment();

View file

@ -79,8 +79,7 @@ class CommentController extends ControllerBase {
* @param \Drupal\comment\CommentInterface $comment
* A comment entity.
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse.
* Redirects to the permalink URL for this comment.
* @return \Symfony\Component\HttpFoundation\RedirectResponse
*/
public function commentApprove(CommentInterface $comment) {
$comment->setPublished(TRUE);
@ -125,9 +124,8 @@ class CommentController extends ControllerBase {
// Find the current display page for this comment.
$page = $this->entityManager()->getStorage('comment')->getDisplayOrdinal($comment, $field_definition->getSetting('default_mode'), $field_definition->getSetting('per_page'));
// @todo: Cleaner sub request handling.
$subrequest_url = $entity->urlInfo()->toString(TRUE);
$subrequest_url = $entity->urlInfo()->setOption('query', ['page' => $page])->toString(TRUE);
$redirect_request = Request::create($subrequest_url->getGeneratedUrl(), 'GET', $request->query->all(), $request->cookies->all(), array(), $request->server->all());
$redirect_request->query->set('page', $page);
// Carry over the session to the subrequest.
if ($session = $request->getSession()) {
$redirect_request->setSession($session);

View file

@ -208,16 +208,18 @@ class Comment extends ContentEntityBase implements CommentInterface {
* {@inheritdoc}
*/
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields['cid'] = BaseFieldDefinition::create('integer')
->setLabel(t('Comment ID'))
->setDescription(t('The comment ID.'))
->setReadOnly(TRUE)
->setSetting('unsigned', TRUE);
/** @var \Drupal\Core\Field\BaseFieldDefinition[] $fields */
$fields = parent::baseFieldDefinitions($entity_type);
$fields['uuid'] = BaseFieldDefinition::create('uuid')
->setLabel(t('UUID'))
->setDescription(t('The comment UUID.'))
->setReadOnly(TRUE);
$fields['cid']->setLabel(t('Comment ID'))
->setDescription(t('The comment ID.'));
$fields['uuid']->setDescription(t('The comment UUID.'));
$fields['comment_type']->setLabel(t('Comment Type'))
->setDescription(t('The comment type.'));
$fields['langcode']->setDescription(t('The comment language code.'));
$fields['pid'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Parent ID'))
@ -229,18 +231,6 @@ class Comment extends ContentEntityBase implements CommentInterface {
->setDescription(t('The ID of the entity of which this comment is a reply.'))
->setRequired(TRUE);
$fields['langcode'] = BaseFieldDefinition::create('language')
->setLabel(t('Language'))
->setDescription(t('The comment language code.'))
->setTranslatable(TRUE)
->setDisplayOptions('view', array(
'type' => 'hidden',
))
->setDisplayOptions('form', array(
'type' => 'language_select',
'weight' => 2,
));
$fields['subject'] = BaseFieldDefinition::create('string')
->setLabel(t('Subject'))
->setTranslatable(TRUE)
@ -312,11 +302,6 @@ class Comment extends ContentEntityBase implements CommentInterface {
->setSetting('is_ascii', TRUE)
->setSetting('max_length', EntityTypeInterface::ID_MAX_LENGTH);
$fields['comment_type'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Comment Type'))
->setDescription(t('The comment type.'))
->setSetting('target_type', 'comment_type');
$fields['field_name'] = BaseFieldDefinition::create('string')
->setLabel(t('Comment field name'))
->setDescription(t('The field name through which this comment was added.'))

View file

@ -151,10 +151,10 @@ class CommentAdminOverview extends FormBase {
'operations' => $this->t('Operations'),
);
$cids = $this->commentStorage->getQuery()
->condition('status', $status)
->tableSort($header)
->pager(50)
->execute();
->condition('status', $status)
->tableSort($header)
->pager(50)
->execute();
/** @var $comments \Drupal\comment\CommentInterface[] */
$comments = $this->commentStorage->loadMultiple($cids);

View file

@ -3,6 +3,7 @@
namespace Drupal\comment\Plugin\Field\FieldFormatter;
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityFormBuilderInterface;
use Drupal\Core\Field\FieldItemListInterface;
@ -36,6 +37,7 @@ class CommentDefaultFormatter extends FormatterBase implements ContainerFactoryP
*/
public static function defaultSettings() {
return array(
'view_mode' => 'default',
'pager_id' => 0,
) + parent::defaultSettings();
}
@ -167,7 +169,7 @@ class CommentDefaultFormatter extends FormatterBase implements ContainerFactoryP
$comments_per_page = $comment_settings['per_page'];
$comments = $this->storage->loadThread($entity, $field_name, $mode, $comments_per_page, $this->getSetting('pager_id'));
if ($comments) {
$build = $this->viewBuilder->viewMultiple($comments);
$build = $this->viewBuilder->viewMultiple($comments, $this->getSetting('view_mode'));
$build['pager']['#type'] = 'pager';
// CommentController::commentPermalink() calculates the page number
// where a specific comment appears and does a subrequest pointing to
@ -217,6 +219,16 @@ class CommentDefaultFormatter extends FormatterBase implements ContainerFactoryP
*/
public function settingsForm(array $form, FormStateInterface $form_state) {
$element = array();
$view_modes = $this->getViewModes();
$element['view_mode'] = [
'#type' => 'select',
'#title' => $this->t('Comments view mode'),
'#description' => $this->t('Select the view mode used to show the list of comments.'),
'#default_value' => $this->getSetting('view_mode'),
'#options' => $view_modes,
// Only show the select element when there are more than one options.
'#access' => count($view_modes) > 1,
];
$element['pager_id'] = array(
'#type' => 'select',
'#title' => $this->t('Pager ID'),
@ -231,13 +243,41 @@ class CommentDefaultFormatter extends FormatterBase implements ContainerFactoryP
* {@inheritdoc}
*/
public function settingsSummary() {
// Only show a summary if we're using a non-standard pager id.
if ($this->getSetting('pager_id')) {
return array($this->t('Pager ID: @id', array(
'@id' => $this->getSetting('pager_id'),
)));
$view_mode = $this->getSetting('view_mode');
$view_modes = $this->getViewModes();
$view_mode_label = isset($view_modes[$view_mode]) ? $view_modes[$view_mode] : 'default';
$summary = [$this->t('Comment view mode: @mode', ['@mode' => $view_mode_label])];
if ($pager_id = $this->getSetting('pager_id')) {
$summary[] = $this->t('Pager ID: @id', ['@id' => $pager_id]);
}
return array();
return $summary;
}
/**
* {@inheritdoc}
*/
public function calculateDependencies() {
$dependencies = parent::calculateDependencies();
if ($mode = $this->getSetting('view_mode')) {
if ($bundle = $this->getFieldSetting('comment_type')) {
/** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display */
if ($display = EntityViewDisplay::load("comment.$bundle.$mode")) {
$dependencies[$display->getConfigDependencyKey()][] = $display->getConfigDependencyName();
}
}
}
return $dependencies;
}
/**
* Provides a list of comment view modes for the configured comment type.
*
* @return array
* Associative array keyed by view mode key and having the view mode label
* as value.
*/
protected function getViewModes() {
return $this->entityManager->getViewModeOptionsByBundle('comment', $this->getFieldSetting('comment_type'));
}
}

View file

@ -29,12 +29,12 @@ class CommentActionsTest extends CommentTestBase {
$comment = $this->postComment($this->node, $comment_text, $subject);
// Unpublish a comment.
$action = entity_load('action', 'comment_unpublish_action');
$action = Action::load('comment_unpublish_action');
$action->execute(array($comment));
$this->assertTrue($comment->isPublished() === FALSE, 'Comment was unpublished');
// Publish a comment.
$action = entity_load('action', 'comment_publish_action');
$action = Action::load('comment_publish_action');
$action->execute(array($comment));
$this->assertTrue($comment->isPublished() === TRUE, 'Comment was published');
}

View file

@ -5,6 +5,9 @@ namespace Drupal\comment\Tests;
use Drupal\comment\CommentManagerInterface;
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\comment\Entity\Comment;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\Core\Entity\Entity\EntityViewMode;
use Drupal\user\RoleInterface;
use Drupal\filter\Entity\FilterFormat;
@ -292,4 +295,53 @@ class CommentInterfaceTest extends CommentTestBase {
$this->assertEqual('(No subject)', Comment::load(2)->getSubject());
}
/**
* Tests the comment formatter configured with a custom comment view mode.
*/
public function testViewMode() {
$this->drupalLogin($this->webUser);
$this->drupalGet($this->node->toUrl());
$comment_text = $this->randomMachineName();
// Post a comment.
$this->postComment($this->node, $comment_text);
// Comment displayed in 'default' display mode found and has body text.
$comment_element = $this->cssSelect('.comment-wrapper');
$this->assertTrue(!empty($comment_element));
$this->assertRaw('<p>' . $comment_text . '</p>');
// Create a new comment entity view mode.
$mode = Unicode::strtolower($this->randomMachineName());
EntityViewMode::create([
'targetEntityType' => 'comment',
'id' => "comment.$mode",
])->save();
// Create the corresponding entity view display for article node-type. Note
// that this new view display mode doesn't contain the comment body.
EntityViewDisplay::create([
'targetEntityType' => 'comment',
'bundle' => 'comment',
'mode' => $mode,
])->setStatus(TRUE)->save();
/** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $node_display */
$node_display = EntityViewDisplay::load('node.article.default');
$formatter = $node_display->getComponent('comment');
// Change the node comment field formatter to use $mode mode instead of
// 'default' mode.
$formatter['settings']['view_mode'] = $mode;
$node_display
->setComponent('comment', $formatter)
->save();
// Reloading the node page to show the same node with its same comment but
// with a different display mode.
$this->drupalGet($this->node->toUrl());
// The comment should exist but without the body text because we used $mode
// mode this time.
$comment_element = $this->cssSelect('.comment-wrapper');
$this->assertTrue(!empty($comment_element));
$this->assertNoRaw('<p>' . $comment_text . '</p>');
}
}

View file

@ -66,7 +66,7 @@ class CommentLinksTest extends CommentTestBase {
'subject' => $this->randomMachineName(),
'hostname' => '127.0.0.1',
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
'comment_body' => array(LanguageInterface::LANGCODE_NOT_SPECIFIED => array($this->randomMachineName())),
'comment_body' => array(array('value' => $this->randomMachineName())),
));
$comment->save();
$this->comment = $comment;
@ -101,6 +101,26 @@ class CommentLinksTest extends CommentTestBase {
$this->assertLink('Add new comment');
}
// Change weight to make links go before comment body.
entity_get_display('comment', 'comment', 'default')
->setComponent('links', array('weight' => -100))
->save();
$this->drupalGet($this->node->urlInfo());
$element = $this->cssSelect('article.js-comment > div');
// Get last child element.
$element = end($element[0]);
$this->assertIdentical($element[0]->getName(), 'div', 'Last element is comment body.');
// Change weight to make links go after comment body.
entity_get_display('comment', 'comment', 'default')
->setComponent('links', array('weight' => 100))
->save();
$this->drupalGet($this->node->urlInfo());
$element = $this->cssSelect('article.js-comment > div');
// Get last child element.
$element = end($element[0]);
$this->assertIdentical($element[0]->getName(), 'ul', 'Last element is comment links.');
// Make sure we can hide node links.
entity_get_display('node', $this->node->bundle(), 'default')
->removeComponent('links')

View file

@ -90,6 +90,38 @@ class CommentPagerTest extends CommentTestBase {
$this->drupalLogout();
}
/**
* Confirms comment paging works correctly with flat and threaded comments.
*/
function testCommentPermalink() {
$this->drupalLogin($this->adminUser);
// Set comment variables.
$this->setCommentForm(TRUE);
$this->setCommentSubject(TRUE);
$this->setCommentPreview(DRUPAL_DISABLED);
// Create a node and three comments.
$node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1));
$comments = array();
$comments[] = $this->postComment($node, 'comment 1: ' . $this->randomMachineName(), $this->randomMachineName(), TRUE);
$comments[] = $this->postComment($node, 'comment 2: ' . $this->randomMachineName(), $this->randomMachineName(), TRUE);
$comments[] = $this->postComment($node, 'comment 3: ' . $this->randomMachineName(), $this->randomMachineName(), TRUE);
$this->setCommentSettings('default_mode', CommentManagerInterface::COMMENT_MODE_FLAT, 'Comment paging changed.');
// Set comments to one per page so that we are able to test paging without
// needing to insert large numbers of comments.
$this->setCommentsPerPage(1);
// Navigate to each comment permalink as anonymous and assert it appears on
// the page.
foreach ($comments as $index => $comment) {
$this->drupalGet($comment->toUrl());
$this->assertTrue($this->commentExists($comment), sprintf('Comment %d appears on page %d.', $index + 1, $index + 1));
}
}
/**
* Tests comment ordering and threading.
*/
@ -283,6 +315,7 @@ class CommentPagerTest extends CommentTestBase {
'weight' => 30,
'settings' => array(
'pager_id' => 1,
'view_mode' => 'default',
)
))
->save();

View file

@ -111,7 +111,7 @@ abstract class CommentTestBase extends WebTestBase {
$edit['comment_body[0][value]'] = $comment;
if ($entity !== NULL) {
$field = FieldConfig::loadByName('node', $entity->bundle(), $field_name);
$field = FieldConfig::loadByName($entity->getEntityTypeId(), $entity->bundle(), $field_name);
}
else {
$field = FieldConfig::loadByName('node', 'article', $field_name);
@ -120,7 +120,7 @@ abstract class CommentTestBase extends WebTestBase {
// Must get the page before we test for fields.
if ($entity !== NULL) {
$this->drupalGet('comment/reply/node/' . $entity->id() . '/' . $field_name);
$this->drupalGet('comment/reply/' . $entity->getEntityTypeId() . '/' . $entity->id() . '/' . $field_name);
}
// Determine the visibility of subject form field.

View file

@ -29,8 +29,11 @@ trait CommentTestTrait {
* CommentItemInterface::OPEN.
* @param string $comment_type_id
* (optional) ID of comment type to use. Defaults to 'comment'.
* @param string $comment_view_mode
* (optional) The comment view mode to be used in comment field formatter.
* Defaults to 'full'.
*/
public function addDefaultCommentField($entity_type, $bundle, $field_name = 'comment', $default_value = CommentItemInterface::OPEN, $comment_type_id = 'comment') {
public function addDefaultCommentField($entity_type, $bundle, $field_name = 'comment', $default_value = CommentItemInterface::OPEN, $comment_type_id = 'comment', $comment_view_mode = 'full') {
$entity_manager = \Drupal::entityManager();
// Create the comment type if needed.
$comment_type_storage = $entity_manager->getStorage('comment_type');
@ -106,6 +109,7 @@ trait CommentTestTrait {
'label' => 'above',
'type' => 'comment_default',
'weight' => 20,
'settings' => array('view_mode' => $comment_view_mode),
))
->save();
foreach ($entity_manager->getViewModes($entity_type) as $id => $view_mode) {

View file

@ -59,6 +59,12 @@ class CommentTitleTest extends CommentTestBase {
$this->assertTrue($this->commentExists($comment1), 'Comment #1. Comment found.');
// Tests that markup is created for comment with heading.
$this->assertPattern('|<h3[^>]*><a[^>]*>' . $subject_text . '</a></h3>|', 'Comment title is rendered in h3 when title populated.');
// Tests that the comment's title link is the permalink of the comment.
$comment_permalink = $this->cssSelect('.permalink');
$comment_permalink = (string) $comment_permalink[0]['href'];
// Tests that the comment's title link contains the url fragment.
$this->assertTrue(strpos($comment_permalink, '#comment-' . $comment1->id()), "The comment's title link contains the url fragment.");
$this->assertEqual($comment1->permalink()->toString(), $comment_permalink, "The comment's title has the correct link.");
}
}

View file

@ -2,12 +2,16 @@
namespace Drupal\comment\Tests;
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\UrlHelper;
use Drupal\comment\Entity\Comment;
use Drupal\Core\Render\BubbleableMetadata;
use Drupal\node\Entity\Node;
use Drupal\taxonomy\Entity\Term;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\user\Entity\User;
/**
* Generates text using placeholders for dummy content to check comment token
@ -16,6 +20,12 @@ use Drupal\node\Entity\Node;
* @group comment
*/
class CommentTokenReplaceTest extends CommentTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['taxonomy'];
/**
* Creates a comment, then tests the tokens generated from it.
*/
@ -27,6 +37,12 @@ class CommentTokenReplaceTest extends CommentTestBase {
'language' => $language_interface,
);
// Setup vocabulary.
Vocabulary::create([
'vid' => 'tags',
'name' => 'Tags',
])->save();
// Change the title of the admin user.
$this->adminUser->name->value = 'This is a title with some special & > " stuff.';
$this->adminUser->save();
@ -122,18 +138,43 @@ class CommentTokenReplaceTest extends CommentTestBase {
$input = '[comment:author]';
$output = $token_service->replace($input, array('comment' => $comment), array('langcode' => $language_interface->getId()));
$this->assertEqual($output, Html::escape($author_name), format_string('Comment author token %token replaced.', array('%token' => $input)));
// Add comment field to user and term entities.
$this->addDefaultCommentField('user', 'user', 'comment', CommentItemInterface::OPEN, 'comment_user');
$this->addDefaultCommentField('taxonomy_term', 'tags', 'comment', CommentItemInterface::OPEN, 'comment_term');
// Load node so comment_count gets computed.
// Create a user and a comment.
$user = User::create(['name' => 'alice']);
$user->save();
$this->postComment($user, 'user body', 'user subject', TRUE);
// Create a term and a comment.
$term = Term::create([
'vid' => 'tags',
'name' => 'term',
]);
$term->save();
$this->postComment($term, 'term body', 'term subject', TRUE);
// Load node, user and term again so comment_count gets computed.
$node = Node::load($node->id());
$user = User::load($user->id());
$term = Term::load($term->id());
// Generate comment tokens for the node (it has 2 comments, both new).
// Generate comment tokens for node (it has 2 comments, both new),
// user and term.
$tests = array();
$tests['[entity:comment-count]'] = 2;
$tests['[entity:comment-count-new]'] = 2;
$tests['[node:comment-count]'] = 2;
$tests['[node:comment-count-new]'] = 2;
$tests['[user:comment-count]'] = 1;
$tests['[user:comment-count-new]'] = 1;
$tests['[term:comment-count]'] = 1;
$tests['[term:comment-count-new]'] = 1;
foreach ($tests as $input => $expected) {
$output = $token_service->replace($input, array('entity' => $node, 'node' => $node), array('langcode' => $language_interface->getId()));
$this->assertEqual($output, $expected, format_string('Node comment token %token replaced.', array('%token' => $input)));
$output = $token_service->replace($input, ['entity' => $node, 'node' => $node, 'user' => $user, 'term' => $term], ['langcode' => $language_interface->getId()]);
$this->assertEqual($output, $expected, format_string('Comment token %token replaced.', ['%token' => $input]));
}
}

View file

@ -146,7 +146,10 @@ class CommentTranslationUITest extends ContentTranslationUITestBase {
* {@inheritdoc}
*/
protected function doTestAuthoringInfo() {
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
$storage = $this->container->get('entity_type.manager')
->getStorage($this->entityTypeId);
$storage->resetCache([$this->entityId]);
$entity = $storage->load($this->entityId);
$languages = $this->container->get('language_manager')->getLanguages();
$values = array();
@ -166,7 +169,8 @@ class CommentTranslationUITest extends ContentTranslationUITestBase {
$this->drupalPostForm($url, $edit, $this->getFormSubmitAction($entity, $langcode));
}
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
$storage->resetCache([$this->entityId]);
$entity = $storage->load($this->entityId);
foreach ($this->langcodes as $langcode) {
$metadata = $this->manager->getTranslationMetadata($entity->getTranslation($langcode));
$this->assertEqual($metadata->getAuthor()->id(), $values[$langcode]['uid'], 'Translation author correctly stored.');
@ -195,7 +199,10 @@ class CommentTranslationUITest extends ContentTranslationUITestBase {
* {@inheritdoc}
*/
protected function doTestTranslationEdit() {
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
$storage = $this->container->get('entity_type.manager')
->getStorage($this->entityTypeId);
$storage->resetCache([$this->entityId]);
$entity = $storage->load($this->entityId);
$languages = $this->container->get('language_manager')->getLanguages();
foreach ($this->langcodes as $langcode) {

View file

@ -0,0 +1,53 @@
<?php
namespace Drupal\comment\Tests\Update;
use Drupal\system\Tests\Update\UpdatePathTestBase;
/**
* Tests that comment settings are properly updated during database updates.
*
* @group comment
*/
class CommentUpdateTest extends UpdatePathTestBase {
/**
* {@inheritdoc}
*/
protected function setDatabaseDumpFiles() {
$this->databaseDumpFiles = [
__DIR__ . '/../../../../system/tests/fixtures/update/drupal-8-rc1.filled.standard.php.gz',
];
}
/**
* Tests comment_update_8200().
*
* @see comment_update_8200()
*/
public function testCommentUpdate8101() {
// Load the 'node.article.default' entity view display config, and check
// that component 'comment' does not contain the 'view_mode' setting.
$config = $this->config('core.entity_view_display.node.article.default');
$this->assertNull($config->get('content.comment.settings.view_mode'));
// Load the 'node.forum.default' entity view display config, and check that
// component 'comment_forum' does not contain the 'view_mode' setting.
$config = $this->config('core.entity_view_display.node.forum.default');
$this->assertNull($config->get('content.comment_forum.settings.view_mode'));
// Run updates.
$this->runUpdates();
// Check that 'node.article.default' entity view display setting 'view_mode'
// has the value 'default'.
$config = $this->config('core.entity_view_display.node.article.default');
$this->assertIdentical($config->get('content.comment.settings.view_mode'), 'default');
// Check that 'node.forum.default' entity view display setting 'view_mode'
// has the value 'default'.
$config = $this->config('core.entity_view_display.node.forum.default');
$this->assertIdentical($config->get('content.comment_forum.settings.view_mode'), 'default');
}
}