updated core to 8.6.1 via composer
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
* Attaches comment behaviors to the entity form.
|
||||
*/
|
||||
|
||||
(function ($, Drupal) {
|
||||
(function($, Drupal) {
|
||||
/**
|
||||
*
|
||||
* @type {Drupal~behavior}
|
||||
@@ -11,7 +11,16 @@
|
||||
Drupal.behaviors.commentFieldsetSummaries = {
|
||||
attach(context) {
|
||||
const $context = $(context);
|
||||
$context.find('fieldset.comment-entity-settings-form').drupalSetSummary(context => Drupal.checkPlain($(context).find('.js-form-item-comment input:checked').next('label').text()));
|
||||
$context
|
||||
.find('fieldset.comment-entity-settings-form')
|
||||
.drupalSetSummary(context =>
|
||||
Drupal.checkPlain(
|
||||
$(context)
|
||||
.find('.js-form-item-comment input:checked')
|
||||
.next('label')
|
||||
.text(),
|
||||
),
|
||||
);
|
||||
},
|
||||
};
|
||||
}(jQuery, Drupal));
|
||||
})(jQuery, Drupal);
|
||||
|
||||
@@ -5,5 +5,5 @@ package: Core
|
||||
version: VERSION
|
||||
core: 8.x
|
||||
dependencies:
|
||||
- text
|
||||
- drupal:text
|
||||
configure: comment.admin
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
* Install, update and uninstall functions for the Comment module.
|
||||
*/
|
||||
|
||||
use Drupal\comment\Entity\Comment;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\StringTranslation\PluralTranslatableMarkup;
|
||||
use Drupal\Core\StringTranslation\TranslatableMarkup;
|
||||
@@ -195,3 +196,14 @@ function comment_update_8400() {
|
||||
$entity_definition_update_manager = \Drupal::service('entity.definition_update_manager');
|
||||
$entity_definition_update_manager->updateFieldStorageDefinition($entity_definition_update_manager->getFieldStorageDefinition('status', 'comment'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the comment hostname base field to use a default value callback.
|
||||
*/
|
||||
function comment_update_8600() {
|
||||
$entity_definition_update_manager = \Drupal::entityDefinitionUpdateManager();
|
||||
/** @var \Drupal\Core\Field\BaseFieldDefinition $field_storage_definition */
|
||||
$field_storage_definition = $entity_definition_update_manager->getFieldStorageDefinition('hostname', 'comment');
|
||||
$field_storage_definition->setDefaultValueCallback(Comment::class . '::getDefaultHostname');
|
||||
$entity_definition_update_manager->updateFieldStorageDefinition($field_storage_definition);
|
||||
}
|
||||
|
||||
@@ -268,7 +268,7 @@ function comment_node_view_alter(array &$build, EntityInterface $node, EntityVie
|
||||
* content language of the current request.
|
||||
*
|
||||
* @return array
|
||||
* An array as expected by drupal_render().
|
||||
* An array as expected by \Drupal\Core\Render\RendererInterface::render().
|
||||
*
|
||||
* @deprecated in Drupal 8.x and will be removed before Drupal 9.0.
|
||||
* Use \Drupal::entityManager()->getViewBuilder('comment')->view().
|
||||
@@ -291,12 +291,13 @@ function comment_view(CommentInterface $comment, $view_mode = 'full', $langcode
|
||||
* Defaults to NULL.
|
||||
*
|
||||
* @return array
|
||||
* An array in the format expected by drupal_render().
|
||||
* An array in the format expected by
|
||||
* \Drupal\Core\Render\RendererInterface::render().
|
||||
*
|
||||
* @deprecated in Drupal 8.x and will be removed before Drupal 9.0.
|
||||
* Use \Drupal::entityManager()->getViewBuilder('comment')->viewMultiple().
|
||||
*
|
||||
* @see drupal_render()
|
||||
* @see \Drupal\Core\Render\RendererInterface::render()
|
||||
*/
|
||||
function comment_view_multiple($comments, $view_mode = 'full', $langcode = NULL) {
|
||||
return entity_view_multiple($comments, $view_mode, $langcode);
|
||||
@@ -522,7 +523,7 @@ function comment_user_cancel($edit, $account, $method) {
|
||||
case 'user_cancel_block_unpublish':
|
||||
$comments = entity_load_multiple_by_properties('comment', ['uid' => $account->id()]);
|
||||
foreach ($comments as $comment) {
|
||||
$comment->setPublished(CommentInterface::NOT_PUBLISHED);
|
||||
$comment->setUnpublished();
|
||||
$comment->save();
|
||||
}
|
||||
break;
|
||||
@@ -558,7 +559,7 @@ function comment_user_predelete($account) {
|
||||
* The current state of the form.
|
||||
*
|
||||
* @return array
|
||||
* An array as expected by drupal_render().
|
||||
* An array as expected by \Drupal\Core\Render\RendererInterface::render().
|
||||
*/
|
||||
function comment_preview(CommentInterface $comment, FormStateInterface $form_state) {
|
||||
$preview_build = [];
|
||||
|
||||
@@ -59,8 +59,18 @@ comment.multiple_delete_confirm:
|
||||
defaults:
|
||||
_title: 'Delete'
|
||||
_form: '\Drupal\comment\Form\ConfirmDeleteMultiple'
|
||||
entity_type_id: 'comment'
|
||||
requirements:
|
||||
_permission: 'administer comments'
|
||||
_entity_delete_multiple_access: 'comment'
|
||||
|
||||
entity.comment.delete_multiple_form:
|
||||
path: '/admin/content/comment/delete'
|
||||
defaults:
|
||||
_title: 'Delete'
|
||||
_form: '\Drupal\comment\Form\ConfirmDeleteMultiple'
|
||||
entity_type_id: 'comment'
|
||||
requirements:
|
||||
_entity_delete_multiple_access: 'comment'
|
||||
|
||||
comment.reply:
|
||||
path: '/comment/reply/{entity_type}/{entity}/{field_name}/{pid}'
|
||||
|
||||
@@ -179,7 +179,7 @@ function comment_tokens($type, $tokens, array $data, array $options, BubbleableM
|
||||
|
||||
// Comment related URLs.
|
||||
case 'url':
|
||||
$url_options['fragment'] = 'comment-' . $comment->id();
|
||||
$url_options['fragment'] = 'comment-' . $comment->id();
|
||||
$replacements[$original] = $comment->url('canonical', $url_options);
|
||||
break;
|
||||
|
||||
|
||||
@@ -6,5 +6,5 @@ dependencies:
|
||||
id: comment_delete_action
|
||||
label: 'Delete comment'
|
||||
type: comment
|
||||
plugin: comment_delete_action
|
||||
plugin: entity:delete_action:comment
|
||||
configuration: { }
|
||||
|
||||
@@ -44,6 +44,8 @@ action.configuration.comment_unpublish_action:
|
||||
type: action_configuration_default
|
||||
label: 'Unpublish comment configuration'
|
||||
|
||||
# @deprecated in Drupal 8.6.x, to be removed before Drupal 9.0.0.
|
||||
# @see https://www.drupal.org/node/2934349
|
||||
action.configuration.comment_delete_action:
|
||||
type: action_configuration_default
|
||||
label: 'Delete comment configuration'
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Attaches behaviors for the Comment module's "by-viewer" class.
|
||||
*/
|
||||
|
||||
(function ($, Drupal, drupalSettings) {
|
||||
(function($, Drupal, drupalSettings) {
|
||||
/**
|
||||
* Add 'by-viewer' class to comments written by the current user.
|
||||
*
|
||||
@@ -13,10 +13,13 @@
|
||||
attach(context) {
|
||||
const currentUserID = parseInt(drupalSettings.user.uid, 10);
|
||||
$('[data-comment-user-id]')
|
||||
.filter(function () {
|
||||
return parseInt(this.getAttribute('data-comment-user-id'), 10) === currentUserID;
|
||||
.filter(function() {
|
||||
return (
|
||||
parseInt(this.getAttribute('data-comment-user-id'), 10) ===
|
||||
currentUserID
|
||||
);
|
||||
})
|
||||
.addClass('by-viewer');
|
||||
},
|
||||
};
|
||||
}(jQuery, Drupal, drupalSettings));
|
||||
})(jQuery, Drupal, drupalSettings);
|
||||
|
||||
@@ -6,47 +6,7 @@
|
||||
* installed.
|
||||
*/
|
||||
|
||||
(function ($, Drupal, window) {
|
||||
/**
|
||||
* Renders "new" comment indicators wherever necessary.
|
||||
*
|
||||
* @type {Drupal~behavior}
|
||||
*
|
||||
* @prop {Drupal~behaviorAttach} attach
|
||||
* Attaches "new" comment indicators behavior.
|
||||
*/
|
||||
Drupal.behaviors.commentNewIndicator = {
|
||||
attach(context) {
|
||||
// Collect all "new" comment indicator placeholders (and their
|
||||
// corresponding node IDs) newer than 30 days ago that have not already
|
||||
// been read after their last comment timestamp.
|
||||
const nodeIDs = [];
|
||||
const $placeholders = $(context)
|
||||
.find('[data-comment-timestamp]')
|
||||
.once('history')
|
||||
.filter(function () {
|
||||
const $placeholder = $(this);
|
||||
const commentTimestamp = parseInt($placeholder.attr('data-comment-timestamp'), 10);
|
||||
const nodeID = $placeholder.closest('[data-history-node-id]').attr('data-history-node-id');
|
||||
if (Drupal.history.needsServerCheck(nodeID, commentTimestamp)) {
|
||||
nodeIDs.push(nodeID);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
if ($placeholders.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Fetch the node read timestamps from the server.
|
||||
Drupal.history.fetchTimestamps(nodeIDs, () => {
|
||||
processCommentNewIndicators($placeholders);
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
(function($, Drupal, window) {
|
||||
/**
|
||||
* Processes the markup for "new comment" indicators.
|
||||
*
|
||||
@@ -60,7 +20,10 @@
|
||||
|
||||
$placeholders.each((index, placeholder) => {
|
||||
$placeholder = $(placeholder);
|
||||
const timestamp = parseInt($placeholder.attr('data-comment-timestamp'), 10);
|
||||
const timestamp = parseInt(
|
||||
$placeholder.attr('data-comment-timestamp'),
|
||||
10,
|
||||
);
|
||||
const $node = $placeholder.closest('[data-history-node-id]');
|
||||
const nodeID = $node.attr('data-history-node-id');
|
||||
const lastViewTimestamp = Drupal.history.getLastRead(nodeID);
|
||||
@@ -82,10 +45,58 @@
|
||||
// If the URL points to the first new comment, then scroll to that
|
||||
// comment.
|
||||
if (window.location.hash === '#new') {
|
||||
window.scrollTo(0, $comment.offset().top - Drupal.displace.offsets.top);
|
||||
window.scrollTo(
|
||||
0,
|
||||
$comment.offset().top - Drupal.displace.offsets.top,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}(jQuery, Drupal, window));
|
||||
|
||||
/**
|
||||
* Renders "new" comment indicators wherever necessary.
|
||||
*
|
||||
* @type {Drupal~behavior}
|
||||
*
|
||||
* @prop {Drupal~behaviorAttach} attach
|
||||
* Attaches "new" comment indicators behavior.
|
||||
*/
|
||||
Drupal.behaviors.commentNewIndicator = {
|
||||
attach(context) {
|
||||
// Collect all "new" comment indicator placeholders (and their
|
||||
// corresponding node IDs) newer than 30 days ago that have not already
|
||||
// been read after their last comment timestamp.
|
||||
const nodeIDs = [];
|
||||
const $placeholders = $(context)
|
||||
.find('[data-comment-timestamp]')
|
||||
.once('history')
|
||||
.filter(function() {
|
||||
const $placeholder = $(this);
|
||||
const commentTimestamp = parseInt(
|
||||
$placeholder.attr('data-comment-timestamp'),
|
||||
10,
|
||||
);
|
||||
const nodeID = $placeholder
|
||||
.closest('[data-history-node-id]')
|
||||
.attr('data-history-node-id');
|
||||
if (Drupal.history.needsServerCheck(nodeID, commentTimestamp)) {
|
||||
nodeIDs.push(nodeID);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
if ($placeholders.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Fetch the node read timestamps from the server.
|
||||
Drupal.history.fetchTimestamps(nodeIDs, () => {
|
||||
processCommentNewIndicators($placeholders);
|
||||
});
|
||||
},
|
||||
};
|
||||
})(jQuery, Drupal, window);
|
||||
|
||||
@@ -6,31 +6,6 @@
|
||||
**/
|
||||
|
||||
(function ($, Drupal, window) {
|
||||
Drupal.behaviors.commentNewIndicator = {
|
||||
attach: function attach(context) {
|
||||
var nodeIDs = [];
|
||||
var $placeholders = $(context).find('[data-comment-timestamp]').once('history').filter(function () {
|
||||
var $placeholder = $(this);
|
||||
var commentTimestamp = parseInt($placeholder.attr('data-comment-timestamp'), 10);
|
||||
var nodeID = $placeholder.closest('[data-history-node-id]').attr('data-history-node-id');
|
||||
if (Drupal.history.needsServerCheck(nodeID, commentTimestamp)) {
|
||||
nodeIDs.push(nodeID);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
if ($placeholders.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
Drupal.history.fetchTimestamps(nodeIDs, function () {
|
||||
processCommentNewIndicators($placeholders);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
function processCommentNewIndicators($placeholders) {
|
||||
var isFirstNewComment = true;
|
||||
var newCommentString = Drupal.t('new');
|
||||
@@ -57,4 +32,29 @@
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Drupal.behaviors.commentNewIndicator = {
|
||||
attach: function attach(context) {
|
||||
var nodeIDs = [];
|
||||
var $placeholders = $(context).find('[data-comment-timestamp]').once('history').filter(function () {
|
||||
var $placeholder = $(this);
|
||||
var commentTimestamp = parseInt($placeholder.attr('data-comment-timestamp'), 10);
|
||||
var nodeID = $placeholder.closest('[data-history-node-id]').attr('data-history-node-id');
|
||||
if (Drupal.history.needsServerCheck(nodeID, commentTimestamp)) {
|
||||
nodeIDs.push(nodeID);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
if ($placeholders.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
Drupal.history.fetchTimestamps(nodeIDs, function () {
|
||||
processCommentNewIndicators($placeholders);
|
||||
});
|
||||
}
|
||||
};
|
||||
})(jQuery, Drupal, window);
|
||||
@@ -6,52 +6,7 @@
|
||||
* installed.
|
||||
*/
|
||||
|
||||
(function ($, Drupal, drupalSettings) {
|
||||
/**
|
||||
* Render "X new comments" links wherever necessary.
|
||||
*
|
||||
* @type {Drupal~behavior}
|
||||
*
|
||||
* @prop {Drupal~behaviorAttach} attach
|
||||
* Attaches new comment links behavior.
|
||||
*/
|
||||
Drupal.behaviors.nodeNewCommentsLink = {
|
||||
attach(context) {
|
||||
// Collect all "X new comments" node link placeholders (and their
|
||||
// corresponding node IDs) newer than 30 days ago that have not already
|
||||
// been read after their last comment timestamp.
|
||||
const nodeIDs = [];
|
||||
const $placeholders = $(context)
|
||||
.find('[data-history-node-last-comment-timestamp]')
|
||||
.once('history')
|
||||
.filter(function () {
|
||||
const $placeholder = $(this);
|
||||
const lastCommentTimestamp = parseInt($placeholder.attr('data-history-node-last-comment-timestamp'), 10);
|
||||
const nodeID = $placeholder.closest('[data-history-node-id]').attr('data-history-node-id');
|
||||
if (Drupal.history.needsServerCheck(nodeID, lastCommentTimestamp)) {
|
||||
nodeIDs.push(nodeID);
|
||||
// Hide this placeholder link until it is certain we'll need it.
|
||||
hide($placeholder);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Remove this placeholder link from the DOM because we won't need
|
||||
// it.
|
||||
remove($placeholder);
|
||||
return false;
|
||||
});
|
||||
|
||||
if ($placeholders.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Perform an AJAX request to retrieve node read timestamps.
|
||||
Drupal.history.fetchTimestamps(nodeIDs, () => {
|
||||
processNodeNewCommentLinks($placeholders);
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
(function($, Drupal, drupalSettings) {
|
||||
/**
|
||||
* Hides a "new comment" element.
|
||||
*
|
||||
@@ -62,15 +17,17 @@
|
||||
* The placeholder element passed in as a parameter.
|
||||
*/
|
||||
function hide($placeholder) {
|
||||
return $placeholder
|
||||
// Find the parent <li>.
|
||||
.closest('.comment-new-comments')
|
||||
// Find the preceding <li>, if any, and give it the 'last' class.
|
||||
.prev()
|
||||
.addClass('last')
|
||||
// Go back to the parent <li> and hide it.
|
||||
.end()
|
||||
.hide();
|
||||
return (
|
||||
$placeholder
|
||||
// Find the parent <li>.
|
||||
.closest('.comment-new-comments')
|
||||
// Find the preceding <li>, if any, and give it the 'last' class.
|
||||
.prev()
|
||||
.addClass('last')
|
||||
// Go back to the parent <li> and hide it.
|
||||
.end()
|
||||
.hide()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,15 +50,17 @@
|
||||
* The placeholder element passed in as a parameter.
|
||||
*/
|
||||
function show($placeholder) {
|
||||
return $placeholder
|
||||
// Find the parent <li>.
|
||||
.closest('.comment-new-comments')
|
||||
// Find the preceding <li>, if any, and remove its 'last' class, if any.
|
||||
.prev()
|
||||
.removeClass('last')
|
||||
// Go back to the parent <li> and show it.
|
||||
.end()
|
||||
.show();
|
||||
return (
|
||||
$placeholder
|
||||
// Find the parent <li>.
|
||||
.closest('.comment-new-comments')
|
||||
// Find the preceding <li>, if any, and remove its 'last' class, if any.
|
||||
.prev()
|
||||
.removeClass('last')
|
||||
// Go back to the parent <li> and show it.
|
||||
.end()
|
||||
.show()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -117,9 +76,14 @@
|
||||
let $placeholder;
|
||||
$placeholders.each((index, placeholder) => {
|
||||
$placeholder = $(placeholder);
|
||||
const timestamp = parseInt($placeholder.attr('data-history-node-last-comment-timestamp'), 10);
|
||||
const timestamp = parseInt(
|
||||
$placeholder.attr('data-history-node-last-comment-timestamp'),
|
||||
10,
|
||||
);
|
||||
fieldName = $placeholder.attr('data-history-node-field-name');
|
||||
const nodeID = $placeholder.closest('[data-history-node-id]').attr('data-history-node-id');
|
||||
const nodeID = $placeholder
|
||||
.closest('[data-history-node-id]')
|
||||
.attr('data-history-node-id');
|
||||
const lastViewTimestamp = Drupal.history.getLastRead(nodeID);
|
||||
|
||||
// Queue this placeholder's "X new comments" link to be downloaded from
|
||||
@@ -149,11 +113,17 @@
|
||||
* Data about new comment links indexed by nodeID.
|
||||
*/
|
||||
function render(results) {
|
||||
Object.keys(results || {}).forEach((nodeID) => {
|
||||
Object.keys(results || {}).forEach(nodeID => {
|
||||
if ($placeholdersToUpdate.hasOwnProperty(nodeID)) {
|
||||
$placeholdersToUpdate[nodeID]
|
||||
.attr('href', results[nodeID].first_new_comment_link)
|
||||
.text(Drupal.formatPlural(results[nodeID].new_comment_count, '1 new comment', '@count new comments'))
|
||||
.text(
|
||||
Drupal.formatPlural(
|
||||
results[nodeID].new_comment_count,
|
||||
'1 new comment',
|
||||
'@count new comments',
|
||||
),
|
||||
)
|
||||
.removeClass('hidden');
|
||||
show($placeholdersToUpdate[nodeID]);
|
||||
}
|
||||
@@ -162,8 +132,7 @@
|
||||
|
||||
if (drupalSettings.comment && drupalSettings.comment.newCommentsLinks) {
|
||||
render(drupalSettings.comment.newCommentsLinks.node[fieldName]);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$.ajax({
|
||||
url: Drupal.url('comments/render_new_comments_node_links'),
|
||||
type: 'POST',
|
||||
@@ -173,4 +142,54 @@
|
||||
});
|
||||
}
|
||||
}
|
||||
}(jQuery, Drupal, drupalSettings));
|
||||
|
||||
/**
|
||||
* Render "X new comments" links wherever necessary.
|
||||
*
|
||||
* @type {Drupal~behavior}
|
||||
*
|
||||
* @prop {Drupal~behaviorAttach} attach
|
||||
* Attaches new comment links behavior.
|
||||
*/
|
||||
Drupal.behaviors.nodeNewCommentsLink = {
|
||||
attach(context) {
|
||||
// Collect all "X new comments" node link placeholders (and their
|
||||
// corresponding node IDs) newer than 30 days ago that have not already
|
||||
// been read after their last comment timestamp.
|
||||
const nodeIDs = [];
|
||||
const $placeholders = $(context)
|
||||
.find('[data-history-node-last-comment-timestamp]')
|
||||
.once('history')
|
||||
.filter(function() {
|
||||
const $placeholder = $(this);
|
||||
const lastCommentTimestamp = parseInt(
|
||||
$placeholder.attr('data-history-node-last-comment-timestamp'),
|
||||
10,
|
||||
);
|
||||
const nodeID = $placeholder
|
||||
.closest('[data-history-node-id]')
|
||||
.attr('data-history-node-id');
|
||||
if (Drupal.history.needsServerCheck(nodeID, lastCommentTimestamp)) {
|
||||
nodeIDs.push(nodeID);
|
||||
// Hide this placeholder link until it is certain we'll need it.
|
||||
hide($placeholder);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Remove this placeholder link from the DOM because we won't need
|
||||
// it.
|
||||
remove($placeholder);
|
||||
return false;
|
||||
});
|
||||
|
||||
if ($placeholders.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Perform an AJAX request to retrieve node read timestamps.
|
||||
Drupal.history.fetchTimestamps(nodeIDs, () => {
|
||||
processNodeNewCommentLinks($placeholders);
|
||||
});
|
||||
},
|
||||
};
|
||||
})(jQuery, Drupal, drupalSettings);
|
||||
|
||||
@@ -6,34 +6,6 @@
|
||||
**/
|
||||
|
||||
(function ($, Drupal, drupalSettings) {
|
||||
Drupal.behaviors.nodeNewCommentsLink = {
|
||||
attach: function attach(context) {
|
||||
var nodeIDs = [];
|
||||
var $placeholders = $(context).find('[data-history-node-last-comment-timestamp]').once('history').filter(function () {
|
||||
var $placeholder = $(this);
|
||||
var lastCommentTimestamp = parseInt($placeholder.attr('data-history-node-last-comment-timestamp'), 10);
|
||||
var nodeID = $placeholder.closest('[data-history-node-id]').attr('data-history-node-id');
|
||||
if (Drupal.history.needsServerCheck(nodeID, lastCommentTimestamp)) {
|
||||
nodeIDs.push(nodeID);
|
||||
|
||||
hide($placeholder);
|
||||
return true;
|
||||
}
|
||||
|
||||
remove($placeholder);
|
||||
return false;
|
||||
});
|
||||
|
||||
if ($placeholders.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
Drupal.history.fetchTimestamps(nodeIDs, function () {
|
||||
processNodeNewCommentLinks($placeholders);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
function hide($placeholder) {
|
||||
return $placeholder.closest('.comment-new-comments').prev().addClass('last').end().hide();
|
||||
}
|
||||
@@ -90,4 +62,32 @@
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Drupal.behaviors.nodeNewCommentsLink = {
|
||||
attach: function attach(context) {
|
||||
var nodeIDs = [];
|
||||
var $placeholders = $(context).find('[data-history-node-last-comment-timestamp]').once('history').filter(function () {
|
||||
var $placeholder = $(this);
|
||||
var lastCommentTimestamp = parseInt($placeholder.attr('data-history-node-last-comment-timestamp'), 10);
|
||||
var nodeID = $placeholder.closest('[data-history-node-id]').attr('data-history-node-id');
|
||||
if (Drupal.history.needsServerCheck(nodeID, lastCommentTimestamp)) {
|
||||
nodeIDs.push(nodeID);
|
||||
|
||||
hide($placeholder);
|
||||
return true;
|
||||
}
|
||||
|
||||
remove($placeholder);
|
||||
return false;
|
||||
});
|
||||
|
||||
if ($placeholders.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
Drupal.history.fetchTimestamps(nodeIDs, function () {
|
||||
processNodeNewCommentLinks($placeholders);
|
||||
});
|
||||
}
|
||||
};
|
||||
})(jQuery, Drupal, drupalSettings);
|
||||
@@ -4,6 +4,7 @@ audit: true
|
||||
migration_tags:
|
||||
- Drupal 7
|
||||
- Content
|
||||
class: Drupal\comment\Plugin\migrate\D7Comment
|
||||
source:
|
||||
plugin: d7_comment
|
||||
constants:
|
||||
|
||||
@@ -45,7 +45,12 @@ class CommentAccessControlHandler extends EntityAccessControlHandler {
|
||||
return $access_result;
|
||||
|
||||
case 'update':
|
||||
return AccessResult::allowedIf($account->id() && $account->id() == $entity->getOwnerId() && $entity->isPublished() && $account->hasPermission('edit own comments'))->cachePerPermissions()->cachePerUser()->addCacheableDependency($entity);
|
||||
$access_result = AccessResult::allowedIf($account->id() && $account->id() == $entity->getOwnerId() && $entity->isPublished() && $account->hasPermission('edit own comments'))
|
||||
->cachePerPermissions()->cachePerUser()->addCacheableDependency($entity);
|
||||
if (!$access_result->isAllowed()) {
|
||||
$access_result->setReason("The 'edit own comments' permission is required, the user must be the comment author, and the comment must be published.");
|
||||
}
|
||||
return $access_result;
|
||||
|
||||
default:
|
||||
// No opinion.
|
||||
|
||||
@@ -9,7 +9,8 @@ use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\Core\Datetime\DrupalDateTime;
|
||||
use Drupal\Core\Entity\ContentEntityForm;
|
||||
use Drupal\Core\Entity\EntityConstraintViolationListInterface;
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\Entity\EntityFieldManagerInterface;
|
||||
use Drupal\Core\Entity\EntityRepositoryInterface;
|
||||
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Render\RendererInterface;
|
||||
@@ -37,24 +38,32 @@ class CommentForm extends ContentEntityForm {
|
||||
*/
|
||||
protected $renderer;
|
||||
|
||||
/**
|
||||
* The entity field manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityFieldManagerInterface
|
||||
*/
|
||||
protected $entityFieldManager;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static(
|
||||
$container->get('entity.manager'),
|
||||
$container->get('entity.repository'),
|
||||
$container->get('current_user'),
|
||||
$container->get('renderer'),
|
||||
$container->get('entity_type.bundle.info'),
|
||||
$container->get('datetime.time')
|
||||
$container->get('datetime.time'),
|
||||
$container->get('entity_field.manager')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new CommentForm.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
|
||||
* The entity manager service.
|
||||
* @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository
|
||||
* The entity repository.
|
||||
* @param \Drupal\Core\Session\AccountInterface $current_user
|
||||
* The current user.
|
||||
* @param \Drupal\Core\Render\RendererInterface $renderer
|
||||
@@ -64,10 +73,11 @@ class CommentForm extends ContentEntityForm {
|
||||
* @param \Drupal\Component\Datetime\TimeInterface $time
|
||||
* The time service.
|
||||
*/
|
||||
public function __construct(EntityManagerInterface $entity_manager, AccountInterface $current_user, RendererInterface $renderer, EntityTypeBundleInfoInterface $entity_type_bundle_info = NULL, TimeInterface $time = NULL) {
|
||||
parent::__construct($entity_manager, $entity_type_bundle_info, $time);
|
||||
public function __construct(EntityRepositoryInterface $entity_repository, AccountInterface $current_user, RendererInterface $renderer, EntityTypeBundleInfoInterface $entity_type_bundle_info = NULL, TimeInterface $time = NULL, EntityFieldManagerInterface $entity_field_manager = NULL) {
|
||||
parent::__construct($entity_repository, $entity_type_bundle_info, $time);
|
||||
$this->currentUser = $current_user;
|
||||
$this->renderer = $renderer;
|
||||
$this->entityFieldManager = $entity_field_manager ?: \Drupal::service('entity_field.manager');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,9 +86,9 @@ class CommentForm extends ContentEntityForm {
|
||||
public function form(array $form, FormStateInterface $form_state) {
|
||||
/** @var \Drupal\comment\CommentInterface $comment */
|
||||
$comment = $this->entity;
|
||||
$entity = $this->entityManager->getStorage($comment->getCommentedEntityTypeId())->load($comment->getCommentedEntityId());
|
||||
$entity = $this->entityTypeManager->getStorage($comment->getCommentedEntityTypeId())->load($comment->getCommentedEntityId());
|
||||
$field_name = $comment->getFieldName();
|
||||
$field_definition = $this->entityManager->getFieldDefinitions($entity->getEntityTypeId(), $entity->bundle())[$comment->getFieldName()];
|
||||
$field_definition = $this->entityFieldManager->getFieldDefinitions($entity->getEntityTypeId(), $entity->bundle())[$comment->getFieldName()];
|
||||
$config = $this->config('user.settings');
|
||||
|
||||
// In several places within this function, we vary $form on:
|
||||
@@ -369,22 +379,22 @@ class CommentForm extends ContentEntityForm {
|
||||
// Add a log entry.
|
||||
$logger->notice('Comment posted: %subject.', [
|
||||
'%subject' => $comment->getSubject(),
|
||||
'link' => $this->l(t('View'), $comment->urlInfo()->setOption('fragment', 'comment-' . $comment->id()))
|
||||
'link' => $this->l(t('View'), $comment->urlInfo()->setOption('fragment', 'comment-' . $comment->id())),
|
||||
]);
|
||||
|
||||
// Explain the approval queue if necessary.
|
||||
if (!$comment->isPublished()) {
|
||||
if (!$this->currentUser->hasPermission('administer comments')) {
|
||||
drupal_set_message($this->t('Your comment has been queued for review by site administrators and will be published after approval.'));
|
||||
$this->messenger()->addStatus($this->t('Your comment has been queued for review by site administrators and will be published after approval.'));
|
||||
}
|
||||
}
|
||||
else {
|
||||
drupal_set_message($this->t('Your comment has been posted.'));
|
||||
$this->messenger()->addStatus($this->t('Your comment has been posted.'));
|
||||
}
|
||||
$query = [];
|
||||
// Find the current display page for this comment.
|
||||
$field_definition = $this->entityManager->getFieldDefinitions($entity->getEntityTypeId(), $entity->bundle())[$field_name];
|
||||
$page = $this->entityManager->getStorage('comment')->getDisplayOrdinal($comment, $field_definition->getSetting('default_mode'), $field_definition->getSetting('per_page'));
|
||||
$field_definition = $this->entityFieldManager->getFieldDefinitions($entity->getEntityTypeId(), $entity->bundle())[$field_name];
|
||||
$page = $this->entityTypeManager->getStorage('comment')->getDisplayOrdinal($comment, $field_definition->getSetting('default_mode'), $field_definition->getSetting('per_page'));
|
||||
if ($page > 0) {
|
||||
$query['page'] = $page;
|
||||
}
|
||||
@@ -394,7 +404,7 @@ class CommentForm extends ContentEntityForm {
|
||||
}
|
||||
else {
|
||||
$logger->warning('Comment: unauthorized comment submitted or comment submitted to a closed post %subject.', ['%subject' => $comment->getSubject()]);
|
||||
drupal_set_message($this->t('Comment: unauthorized comment submitted or comment submitted to a closed post %subject.', ['%subject' => $comment->getSubject()]), 'error');
|
||||
$this->messenger()->addError($this->t('Comment: unauthorized comment submitted or comment submitted to a closed post %subject.', ['%subject' => $comment->getSubject()]));
|
||||
// Redirect the user to the entity they are commenting on.
|
||||
}
|
||||
$form_state->setRedirectUrl($uri);
|
||||
|
||||
@@ -107,7 +107,7 @@ class CommentLinkBuilder implements CommentLinkBuilderInterface {
|
||||
'title' => $this->formatPlural($entity->get($field_name)->comment_count, '1 comment', '@count comments'),
|
||||
'attributes' => ['title' => $this->t('Jump to the first comment.')],
|
||||
'fragment' => 'comments',
|
||||
'url' => $entity->urlInfo(),
|
||||
'url' => $entity->toUrl(),
|
||||
];
|
||||
if ($this->moduleHandler->moduleExists('history')) {
|
||||
$links['comment-new-comments'] = [
|
||||
@@ -141,7 +141,7 @@ class CommentLinkBuilder implements CommentLinkBuilderInterface {
|
||||
]);
|
||||
}
|
||||
else {
|
||||
$links['comment-add'] += ['url' => $entity->urlInfo()];
|
||||
$links['comment-add'] += ['url' => $entity->toUrl()];
|
||||
}
|
||||
}
|
||||
elseif ($this->currentUser->isAnonymous()) {
|
||||
@@ -174,7 +174,7 @@ class CommentLinkBuilder implements CommentLinkBuilderInterface {
|
||||
]);
|
||||
}
|
||||
else {
|
||||
$links['comment-add']['url'] = $entity->urlInfo();
|
||||
$links['comment-add']['url'] = $entity->toUrl();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace Drupal\comment;
|
||||
|
||||
use Drupal\Core\Cache\CacheBackendInterface;
|
||||
use Drupal\Core\Cache\MemoryCache\MemoryCacheInterface;
|
||||
use Drupal\Core\Database\Connection;
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
@@ -43,9 +44,11 @@ class CommentStorage extends SqlContentEntityStorage implements CommentStorageIn
|
||||
* Cache backend instance to use.
|
||||
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
|
||||
* The language manager.
|
||||
* @param \Drupal\Core\Cache\MemoryCache\MemoryCacheInterface $memory_cache
|
||||
* The memory cache.
|
||||
*/
|
||||
public function __construct(EntityTypeInterface $entity_info, Connection $database, EntityManagerInterface $entity_manager, AccountInterface $current_user, CacheBackendInterface $cache, LanguageManagerInterface $language_manager) {
|
||||
parent::__construct($entity_info, $database, $entity_manager, $cache, $language_manager);
|
||||
public function __construct(EntityTypeInterface $entity_info, Connection $database, EntityManagerInterface $entity_manager, AccountInterface $current_user, CacheBackendInterface $cache, LanguageManagerInterface $language_manager, MemoryCacheInterface $memory_cache) {
|
||||
parent::__construct($entity_info, $database, $entity_manager, $cache, $language_manager, $memory_cache);
|
||||
$this->currentUser = $current_user;
|
||||
}
|
||||
|
||||
@@ -59,7 +62,8 @@ class CommentStorage extends SqlContentEntityStorage implements CommentStorageIn
|
||||
$container->get('entity.manager'),
|
||||
$container->get('current_user'),
|
||||
$container->get('cache.entity'),
|
||||
$container->get('language_manager')
|
||||
$container->get('language_manager'),
|
||||
$container->get('entity.memory_cache')
|
||||
);
|
||||
}
|
||||
|
||||
@@ -67,7 +71,7 @@ class CommentStorage extends SqlContentEntityStorage implements CommentStorageIn
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getMaxThread(CommentInterface $comment) {
|
||||
$query = $this->database->select('comment_field_data', 'c')
|
||||
$query = $this->database->select($this->getDataTable(), 'c')
|
||||
->condition('entity_id', $comment->getCommentedEntityId())
|
||||
->condition('field_name', $comment->getFieldName())
|
||||
->condition('entity_type', $comment->getCommentedEntityTypeId())
|
||||
@@ -81,7 +85,7 @@ class CommentStorage extends SqlContentEntityStorage implements CommentStorageIn
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getMaxThreadPerThread(CommentInterface $comment) {
|
||||
$query = $this->database->select('comment_field_data', 'c')
|
||||
$query = $this->database->select($this->getDataTable(), 'c')
|
||||
->condition('entity_id', $comment->getCommentedEntityId())
|
||||
->condition('field_name', $comment->getFieldName())
|
||||
->condition('entity_type', $comment->getCommentedEntityTypeId())
|
||||
@@ -98,8 +102,9 @@ class CommentStorage extends SqlContentEntityStorage implements CommentStorageIn
|
||||
public function getDisplayOrdinal(CommentInterface $comment, $comment_mode, $divisor = 1) {
|
||||
// Count how many comments (c1) are before $comment (c2) in display order.
|
||||
// This is the 0-based display ordinal.
|
||||
$query = $this->database->select('comment_field_data', 'c1');
|
||||
$query->innerJoin('comment_field_data', 'c2', 'c2.entity_id = c1.entity_id AND c2.entity_type = c1.entity_type AND c2.field_name = c1.field_name');
|
||||
$data_table = $this->getDataTable();
|
||||
$query = $this->database->select($data_table, 'c1');
|
||||
$query->innerJoin($data_table, 'c2', 'c2.entity_id = c1.entity_id AND c2.entity_type = c1.entity_type AND c2.field_name = c1.field_name');
|
||||
$query->addExpression('COUNT(*)', 'count');
|
||||
$query->condition('c2.cid', $comment->id());
|
||||
if (!$this->currentUser->hasPermission('administer comments')) {
|
||||
@@ -133,6 +138,7 @@ class CommentStorage extends SqlContentEntityStorage implements CommentStorageIn
|
||||
public function getNewCommentPageNumber($total_comments, $new_comments, FieldableEntityInterface $entity, $field_name) {
|
||||
$field = $entity->getFieldDefinition($field_name);
|
||||
$comments_per_page = $field->getSetting('per_page');
|
||||
$data_table = $this->getDataTable();
|
||||
|
||||
if ($total_comments <= $comments_per_page) {
|
||||
// Only one page of comments.
|
||||
@@ -146,7 +152,7 @@ class CommentStorage extends SqlContentEntityStorage implements CommentStorageIn
|
||||
// Threaded comments.
|
||||
|
||||
// 1. Find all the threads with a new comment.
|
||||
$unread_threads_query = $this->database->select('comment_field_data', 'comment')
|
||||
$unread_threads_query = $this->database->select($data_table, 'comment')
|
||||
->fields('comment', ['thread'])
|
||||
->condition('entity_id', $entity->id())
|
||||
->condition('entity_type', $entity->getEntityTypeId())
|
||||
@@ -171,7 +177,7 @@ class CommentStorage extends SqlContentEntityStorage implements CommentStorageIn
|
||||
$first_thread = substr($first_thread, 0, -1);
|
||||
|
||||
// Find the number of the first comment of the first unread thread.
|
||||
$count = $this->database->query('SELECT COUNT(*) FROM {comment_field_data} WHERE entity_id = :entity_id
|
||||
$count = $this->database->query('SELECT COUNT(*) FROM {' . $data_table . '} WHERE entity_id = :entity_id
|
||||
AND entity_type = :entity_type
|
||||
AND field_name = :field_name
|
||||
AND status = :status
|
||||
@@ -192,7 +198,7 @@ class CommentStorage extends SqlContentEntityStorage implements CommentStorageIn
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getChildCids(array $comments) {
|
||||
return $this->database->select('comment_field_data', 'c')
|
||||
return $this->database->select($this->getDataTable(), 'c')
|
||||
->fields('c', ['cid'])
|
||||
->condition('pid', array_keys($comments), 'IN')
|
||||
->condition('default_langcode', 1)
|
||||
@@ -258,7 +264,8 @@ class CommentStorage extends SqlContentEntityStorage implements CommentStorageIn
|
||||
* to consider the trailing "/" so we use a substring only.
|
||||
*/
|
||||
public function loadThread(EntityInterface $entity, $field_name, $mode, $comments_per_page = 0, $pager_id = 0) {
|
||||
$query = $this->database->select('comment_field_data', 'c');
|
||||
$data_table = $this->getDataTable();
|
||||
$query = $this->database->select($data_table, 'c');
|
||||
$query->addField('c', 'cid');
|
||||
$query
|
||||
->condition('c.entity_id', $entity->id())
|
||||
@@ -278,7 +285,7 @@ class CommentStorage extends SqlContentEntityStorage implements CommentStorageIn
|
||||
$query->element($pager_id);
|
||||
}
|
||||
|
||||
$count_query = $this->database->select('comment_field_data', 'c');
|
||||
$count_query = $this->database->select($data_table, 'c');
|
||||
$count_query->addExpression('COUNT(*)');
|
||||
$count_query
|
||||
->condition('c.entity_id', $entity->id())
|
||||
@@ -324,7 +331,7 @@ class CommentStorage extends SqlContentEntityStorage implements CommentStorageIn
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getUnapprovedCount() {
|
||||
return $this->database->select('comment_field_data', 'c')
|
||||
return $this->database->select($this->getDataTable(), 'c')
|
||||
->condition('status', CommentInterface::NOT_PUBLISHED, '=')
|
||||
->condition('default_langcode', 1)
|
||||
->countQuery()
|
||||
|
||||
@@ -17,24 +17,26 @@ class CommentStorageSchema extends SqlContentEntityStorageSchema {
|
||||
protected function getEntitySchema(ContentEntityTypeInterface $entity_type, $reset = FALSE) {
|
||||
$schema = parent::getEntitySchema($entity_type, $reset);
|
||||
|
||||
$schema['comment_field_data']['indexes'] += [
|
||||
'comment__status_pid' => ['pid', 'status'],
|
||||
'comment__num_new' => [
|
||||
'entity_id',
|
||||
'entity_type',
|
||||
'comment_type',
|
||||
'status',
|
||||
'created',
|
||||
'cid',
|
||||
'thread',
|
||||
],
|
||||
'comment__entity_langcode' => [
|
||||
'entity_id',
|
||||
'entity_type',
|
||||
'comment_type',
|
||||
'default_langcode',
|
||||
],
|
||||
];
|
||||
if ($data_table = $this->storage->getDataTable()) {
|
||||
$schema[$data_table]['indexes'] += [
|
||||
'comment__status_pid' => ['pid', 'status'],
|
||||
'comment__num_new' => [
|
||||
'entity_id',
|
||||
'entity_type',
|
||||
'comment_type',
|
||||
'status',
|
||||
'created',
|
||||
'cid',
|
||||
'thread',
|
||||
],
|
||||
'comment__entity_langcode' => [
|
||||
'entity_id',
|
||||
'entity_type',
|
||||
'comment_type',
|
||||
'default_langcode',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
return $schema;
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ class CommentTypeForm extends EntityForm {
|
||||
'#default_value' => $comment_type->getTargetEntityTypeId(),
|
||||
'#title' => t('Target entity type'),
|
||||
'#options' => $options,
|
||||
'#description' => t('The target entity type can not be changed after the comment type has been created.')
|
||||
'#description' => t('The target entity type can not be changed after the comment type has been created.'),
|
||||
];
|
||||
}
|
||||
else {
|
||||
@@ -160,12 +160,12 @@ class CommentTypeForm extends EntityForm {
|
||||
|
||||
$edit_link = $this->entity->link($this->t('Edit'));
|
||||
if ($status == SAVED_UPDATED) {
|
||||
drupal_set_message(t('Comment type %label has been updated.', ['%label' => $comment_type->label()]));
|
||||
$this->messenger()->addStatus(t('Comment type %label has been updated.', ['%label' => $comment_type->label()]));
|
||||
$this->logger->notice('Comment type %label has been updated.', ['%label' => $comment_type->label(), 'link' => $edit_link]);
|
||||
}
|
||||
else {
|
||||
$this->commentManager->addBodyField($comment_type->id());
|
||||
drupal_set_message(t('Comment type %label has been added.', ['%label' => $comment_type->label()]));
|
||||
$this->messenger()->addStatus(t('Comment type %label has been added.', ['%label' => $comment_type->label()]));
|
||||
$this->logger->notice('Comment type %label has been added.', ['%label' => $comment_type->label(), 'link' => $edit_link]);
|
||||
}
|
||||
|
||||
|
||||
@@ -98,6 +98,7 @@ class CommentViewBuilder extends EntityViewBuilder {
|
||||
|
||||
// A counter to track the indentation level.
|
||||
$current_indent = 0;
|
||||
$attach_history = $this->moduleHandler->moduleExists('history') && $this->currentUser->isAuthenticated();
|
||||
|
||||
foreach ($entities as $id => $entity) {
|
||||
if ($build[$id]['#comment_threaded']) {
|
||||
@@ -143,7 +144,7 @@ class CommentViewBuilder extends EntityViewBuilder {
|
||||
$build[$id]['#attached'] = [];
|
||||
}
|
||||
$build[$id]['#attached']['library'][] = 'comment/drupal.comment-by-viewer';
|
||||
if ($this->moduleHandler->moduleExists('history') && $this->currentUser->isAuthenticated()) {
|
||||
if ($attach_history && $commented_entity->getEntityTypeId() === 'node') {
|
||||
$build[$id]['#attached']['library'][] = 'comment/drupal.comment-new-indicator';
|
||||
|
||||
// Embed the metadata for the comment "new" indicators on this node.
|
||||
|
||||
@@ -214,7 +214,7 @@ class CommentViewsData extends EntityViewsData {
|
||||
[
|
||||
'field' => 'entity_type',
|
||||
'value' => $type,
|
||||
'table' => 'comment_field_data'
|
||||
'table' => 'comment_field_data',
|
||||
],
|
||||
],
|
||||
],
|
||||
@@ -235,7 +235,7 @@ class CommentViewsData extends EntityViewsData {
|
||||
|
||||
// Define the base group of this table. Fields that don't have a group defined
|
||||
// will go into this field by default.
|
||||
$data['comment_entity_statistics']['table']['group'] = $this->t('Comment Statistics');
|
||||
$data['comment_entity_statistics']['table']['group'] = $this->t('Comment Statistics');
|
||||
|
||||
// Provide a relationship for each entity type except comment.
|
||||
foreach ($entities_types as $type => $entity_type) {
|
||||
|
||||
@@ -82,10 +82,10 @@ class CommentController extends ControllerBase {
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse
|
||||
*/
|
||||
public function commentApprove(CommentInterface $comment) {
|
||||
$comment->setPublished(TRUE);
|
||||
$comment->setPublished();
|
||||
$comment->save();
|
||||
|
||||
drupal_set_message($this->t('Comment approved.'));
|
||||
$this->messenger()->addStatus($this->t('Comment approved.'));
|
||||
$permalink_uri = $comment->permalink();
|
||||
$permalink_uri->setAbsolute();
|
||||
return new RedirectResponse($permalink_uri->toString());
|
||||
|
||||
@@ -56,6 +56,7 @@ use Drupal\user\UserInterface;
|
||||
* links = {
|
||||
* "canonical" = "/comment/{comment}",
|
||||
* "delete-form" = "/comment/{comment}/delete",
|
||||
* "delete-multiple-form" = "/admin/content/comment/delete",
|
||||
* "edit-form" = "/comment/{comment}/edit",
|
||||
* "create" = "/comment",
|
||||
* },
|
||||
@@ -142,10 +143,6 @@ class Comment extends ContentEntityBase implements CommentInterface {
|
||||
$this->threadLock = $lock_name;
|
||||
}
|
||||
$this->setThread($thread);
|
||||
if (!$this->getHostname()) {
|
||||
// Ensure a client host from the current request.
|
||||
$this->setHostname(\Drupal::request()->getClientIP());
|
||||
}
|
||||
}
|
||||
// The entity fields for name and mail have no meaning if the user is not
|
||||
// Anonymous. Set them to NULL to make it clearer that they are not used.
|
||||
@@ -290,7 +287,8 @@ class Comment extends ContentEntityBase implements CommentInterface {
|
||||
->setLabel(t('Hostname'))
|
||||
->setDescription(t("The comment author's hostname."))
|
||||
->setTranslatable(TRUE)
|
||||
->setSetting('max_length', 128);
|
||||
->setSetting('max_length', 128)
|
||||
->setDefaultValueCallback(static::class . '::getDefaultHostname');
|
||||
|
||||
$fields['created'] = BaseFieldDefinition::create('created')
|
||||
->setLabel(t('Created'))
|
||||
@@ -571,4 +569,14 @@ class Comment extends ContentEntityBase implements CommentInterface {
|
||||
return \Drupal::currentUser()->hasPermission('skip comment approval') ? CommentInterface::PUBLISHED : CommentInterface::NOT_PUBLISHED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default value for entity hostname base field.
|
||||
*
|
||||
* @return string
|
||||
* The client host name.
|
||||
*/
|
||||
public static function getDefaultHostname() {
|
||||
return \Drupal::request()->getClientIP();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ use Drupal\comment\CommentTypeInterface;
|
||||
* "delete-form" = "/admin/structure/comment/manage/{comment_type}/delete",
|
||||
* "edit-form" = "/admin/structure/comment/manage/{comment_type}",
|
||||
* "add-form" = "/admin/structure/comment/types/add",
|
||||
* "collection" = "/admin/structure/comment/types",
|
||||
* "collection" = "/admin/structure/comment",
|
||||
* },
|
||||
* config_export = {
|
||||
* "id",
|
||||
|
||||
@@ -279,7 +279,7 @@ class CommentAdminOverview extends FormBase {
|
||||
}
|
||||
$comment->save();
|
||||
}
|
||||
drupal_set_message($this->t('The update has been performed.'));
|
||||
$this->messenger()->addStatus($this->t('The update has been performed.'));
|
||||
$form_state->setRedirect('comment.admin');
|
||||
}
|
||||
else {
|
||||
@@ -290,9 +290,9 @@ class CommentAdminOverview extends FormBase {
|
||||
$info[$comment->id()][$langcode] = $langcode;
|
||||
}
|
||||
$this->tempStoreFactory
|
||||
->get('comment_multiple_delete_confirm')
|
||||
->set($this->currentUser()->id(), $info);
|
||||
$form_state->setRedirect('comment.multiple_delete_confirm');
|
||||
->get('entity_delete_multiple_confirm')
|
||||
->set($this->currentUser()->id() . ':comment', $info);
|
||||
$form_state->setRedirect('entity.comment.delete_multiple_form');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,76 +2,21 @@
|
||||
|
||||
namespace Drupal\comment\Form;
|
||||
|
||||
use Drupal\comment\CommentStorageInterface;
|
||||
use Drupal\Core\TempStore\PrivateTempStoreFactory;
|
||||
use Drupal\Core\Form\ConfirmFormBase;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Entity\Form\DeleteMultipleForm as EntityDeleteMultipleForm;
|
||||
use Drupal\Core\Url;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Provides the comment multiple delete confirmation form.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class ConfirmDeleteMultiple extends ConfirmFormBase {
|
||||
|
||||
/**
|
||||
* The tempstore factory.
|
||||
*
|
||||
* @var \Drupal\Core\TempStore\PrivateTempStoreFactory
|
||||
*/
|
||||
protected $tempStoreFactory;
|
||||
|
||||
/**
|
||||
* The comment storage.
|
||||
*
|
||||
* @var \Drupal\comment\CommentStorageInterface
|
||||
*/
|
||||
protected $commentStorage;
|
||||
|
||||
/**
|
||||
* An array of comments to be deleted.
|
||||
*
|
||||
* @var string[][]
|
||||
*/
|
||||
protected $commentInfo;
|
||||
|
||||
/**
|
||||
* Creates an new ConfirmDeleteMultiple form.
|
||||
*
|
||||
* @param \Drupal\comment\CommentStorageInterface $comment_storage
|
||||
* The comment storage.
|
||||
* @param \Drupal\Core\TempStore\PrivateTempStoreFactory $temp_store_factory
|
||||
* The tempstore factory.
|
||||
*/
|
||||
public function __construct(CommentStorageInterface $comment_storage, PrivateTempStoreFactory $temp_store_factory) {
|
||||
$this->commentStorage = $comment_storage;
|
||||
$this->tempStoreFactory = $temp_store_factory;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static(
|
||||
$container->get('entity.manager')->getStorage('comment'),
|
||||
$container->get('tempstore.private')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFormId() {
|
||||
return 'comment_multiple_delete_confirm';
|
||||
}
|
||||
class ConfirmDeleteMultiple extends EntityDeleteMultipleForm {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getQuestion() {
|
||||
return $this->formatPlural(count($this->commentInfo), 'Are you sure you want to delete this comment and all its children?', 'Are you sure you want to delete these comments and all their children?');
|
||||
return $this->formatPlural(count($this->selection), 'Are you sure you want to delete this comment and all its children?', 'Are you sure you want to delete these comments and all their children?');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -84,116 +29,15 @@ class ConfirmDeleteMultiple extends ConfirmFormBase {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getConfirmText() {
|
||||
return $this->t('Delete');
|
||||
protected function getDeletedMessage($count) {
|
||||
return $this->formatPlural($count, 'Deleted @count comment.', 'Deleted @count comments.');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$this->commentInfo = $this->tempStoreFactory->get('comment_multiple_delete_confirm')->get($this->currentUser()->id());
|
||||
if (empty($this->commentInfo)) {
|
||||
return $this->redirect('comment.admin');
|
||||
}
|
||||
/** @var \Drupal\comment\CommentInterface[] $comments */
|
||||
$comments = $this->commentStorage->loadMultiple(array_keys($this->commentInfo));
|
||||
|
||||
$items = [];
|
||||
foreach ($this->commentInfo as $id => $langcodes) {
|
||||
foreach ($langcodes as $langcode) {
|
||||
$comment = $comments[$id]->getTranslation($langcode);
|
||||
$key = $id . ':' . $langcode;
|
||||
$default_key = $id . ':' . $comment->getUntranslated()->language()->getId();
|
||||
|
||||
// If we have a translated entity we build a nested list of translations
|
||||
// that will be deleted.
|
||||
$languages = $comment->getTranslationLanguages();
|
||||
if (count($languages) > 1 && $comment->isDefaultTranslation()) {
|
||||
$names = [];
|
||||
foreach ($languages as $translation_langcode => $language) {
|
||||
$names[] = $language->getName();
|
||||
unset($items[$id . ':' . $translation_langcode]);
|
||||
}
|
||||
$items[$default_key] = [
|
||||
'label' => [
|
||||
'#markup' => $this->t('@label (Original translation) - <em>The following comment translations will be deleted:</em>', ['@label' => $comment->label()]),
|
||||
],
|
||||
'deleted_translations' => [
|
||||
'#theme' => 'item_list',
|
||||
'#items' => $names,
|
||||
],
|
||||
];
|
||||
}
|
||||
elseif (!isset($items[$default_key])) {
|
||||
$items[$key] = $comment->label();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$form['comments'] = [
|
||||
'#theme' => 'item_list',
|
||||
'#items' => $items,
|
||||
];
|
||||
|
||||
return parent::buildForm($form, $form_state);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||
if ($form_state->getValue('confirm') && !empty($this->commentInfo)) {
|
||||
$total_count = 0;
|
||||
$delete_comments = [];
|
||||
/** @var \Drupal\Core\Entity\ContentEntityInterface[][] $delete_translations */
|
||||
$delete_translations = [];
|
||||
/** @var \Drupal\comment\CommentInterface[] $comments */
|
||||
$comments = $this->commentStorage->loadMultiple(array_keys($this->commentInfo));
|
||||
|
||||
foreach ($this->commentInfo as $id => $langcodes) {
|
||||
foreach ($langcodes as $langcode) {
|
||||
$comment = $comments[$id]->getTranslation($langcode);
|
||||
if ($comment->isDefaultTranslation()) {
|
||||
$delete_comments[$id] = $comment;
|
||||
unset($delete_translations[$id]);
|
||||
$total_count += count($comment->getTranslationLanguages());
|
||||
}
|
||||
elseif (!isset($delete_comments[$id])) {
|
||||
$delete_translations[$id][] = $comment;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($delete_comments) {
|
||||
$this->commentStorage->delete($delete_comments);
|
||||
$this->logger('content')->notice('Deleted @count comments.', ['@count' => count($delete_comments)]);
|
||||
}
|
||||
|
||||
if ($delete_translations) {
|
||||
$count = 0;
|
||||
foreach ($delete_translations as $id => $translations) {
|
||||
$comment = $comments[$id]->getUntranslated();
|
||||
foreach ($translations as $translation) {
|
||||
$comment->removeTranslation($translation->language()->getId());
|
||||
}
|
||||
$comment->save();
|
||||
$count += count($translations);
|
||||
}
|
||||
if ($count) {
|
||||
$total_count += $count;
|
||||
$this->logger('content')->notice('Deleted @count comment translations.', ['@count' => $count]);
|
||||
}
|
||||
}
|
||||
|
||||
if ($total_count) {
|
||||
drupal_set_message($this->formatPlural($total_count, 'Deleted 1 comment.', 'Deleted @count comments.'));
|
||||
}
|
||||
|
||||
$this->tempStoreFactory->get('comment_multiple_delete_confirm')->delete($this->currentUser()->id());
|
||||
}
|
||||
|
||||
$form_state->setRedirectUrl($this->getCancelUrl());
|
||||
protected function getInaccessibleMessage($count) {
|
||||
return $this->formatPlural($count, "@count comment has not been deleted because you do not have the necessary permissions.", "@count comments have not been deleted because you do not have the necessary permissions.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,97 +2,33 @@
|
||||
|
||||
namespace Drupal\comment\Plugin\Action;
|
||||
|
||||
use Drupal\Core\Action\ActionBase;
|
||||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
|
||||
use Drupal\Core\Action\Plugin\Action\DeleteAction;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\Core\TempStore\PrivateTempStoreFactory;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Deletes a comment.
|
||||
*
|
||||
* @deprecated in Drupal 8.6.x, to be removed before Drupal 9.0.0.
|
||||
* Use \Drupal\Core\Action\Plugin\Action\DeleteAction instead.
|
||||
*
|
||||
* @see \Drupal\Core\Action\Plugin\Action\DeleteAction
|
||||
* @see https://www.drupal.org/node/2934349
|
||||
*
|
||||
* @Action(
|
||||
* id = "comment_delete_action",
|
||||
* label = @Translation("Delete comment"),
|
||||
* type = "comment",
|
||||
* confirm_form_route_name = "comment.multiple_delete_confirm"
|
||||
* label = @Translation("Delete comment")
|
||||
* )
|
||||
*/
|
||||
class DeleteComment extends ActionBase implements ContainerFactoryPluginInterface {
|
||||
|
||||
/**
|
||||
* The tempstore object.
|
||||
*
|
||||
* @var \Drupal\Core\TempStore\PrivateTempStore
|
||||
*/
|
||||
protected $tempStore;
|
||||
|
||||
/**
|
||||
* The current user.
|
||||
*
|
||||
* @var \Drupal\Core\Session\AccountInterface
|
||||
*/
|
||||
protected $currentUser;
|
||||
|
||||
/**
|
||||
* Constructs a new DeleteComment object.
|
||||
*
|
||||
* @param array $configuration
|
||||
* A configuration array containing information about the plugin instance.
|
||||
* @param string $plugin_id
|
||||
* The plugin ID for the plugin instance.
|
||||
* @param array $plugin_definition
|
||||
* The plugin implementation definition.
|
||||
* @param \Drupal\Core\TempStore\PrivateTempStoreFactory $temp_store_factory
|
||||
* The tempstore factory.
|
||||
* @param \Drupal\Core\Session\AccountInterface $current_user
|
||||
* The current user.
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, array $plugin_definition, PrivateTempStoreFactory $temp_store_factory, AccountInterface $current_user) {
|
||||
$this->currentUser = $current_user;
|
||||
$this->tempStore = $temp_store_factory->get('comment_multiple_delete_confirm');
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition);
|
||||
}
|
||||
class DeleteComment extends DeleteAction {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
|
||||
return new static(
|
||||
$configuration,
|
||||
$plugin_id,
|
||||
$plugin_definition,
|
||||
$container->get('tempstore.private'),
|
||||
$container->get('current_user')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function executeMultiple(array $entities) {
|
||||
$info = [];
|
||||
/** @var \Drupal\comment\CommentInterface $comment */
|
||||
foreach ($entities as $comment) {
|
||||
$langcode = $comment->language()->getId();
|
||||
$info[$comment->id()][$langcode] = $langcode;
|
||||
}
|
||||
$this->tempStore->set($this->currentUser->id(), $info);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function execute($entity = NULL) {
|
||||
$this->executeMultiple([$entity]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function access($comment, AccountInterface $account = NULL, $return_as_object = FALSE) {
|
||||
/** @var \Drupal\comment\CommentInterface $comment */
|
||||
return $comment->access('delete', $account, $return_as_object);
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, PrivateTempStoreFactory $temp_store_factory, AccountInterface $current_user) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition, $entity_type_manager, $temp_store_factory, $current_user);
|
||||
@trigger_error(__NAMESPACE__ . '\DeleteComment is deprecated in Drupal 8.6.x, will be removed before Drupal 9.0.0. Use \Drupal\Core\Action\Plugin\Action\DeleteAction instead. See https://www.drupal.org/node/2934349.', E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ class UnpublishByKeywordComment extends ConfigurableActionBase implements Contai
|
||||
$text = $this->renderer->renderPlain($build);
|
||||
foreach ($this->configuration['keywords'] as $keyword) {
|
||||
if (strpos($text, $keyword) !== FALSE) {
|
||||
$comment->setPublished(FALSE);
|
||||
$comment->setUnpublished();
|
||||
$comment->save();
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ class CommentSelection extends DefaultSelection {
|
||||
|
||||
// In order to create a referenceable comment, it needs to published.
|
||||
/** @var \Drupal\comment\CommentInterface $comment */
|
||||
$comment->setPublished(TRUE);
|
||||
$comment->setPublished();
|
||||
|
||||
return $comment;
|
||||
}
|
||||
|
||||
@@ -117,9 +117,8 @@ class CommentItem extends FieldItemBase implements CommentItemInterface {
|
||||
'#title' => t('Comments per page'),
|
||||
'#default_value' => $settings['per_page'],
|
||||
'#required' => TRUE,
|
||||
'#min' => 10,
|
||||
'#min' => 1,
|
||||
'#max' => 1000,
|
||||
'#step' => 10,
|
||||
];
|
||||
$element['anonymous'] = [
|
||||
'#type' => 'select',
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\comment\Plugin\migrate;
|
||||
|
||||
use Drupal\migrate_drupal\Plugin\migrate\FieldMigration;
|
||||
|
||||
/**
|
||||
* Migration plugin for Drupal 7 comments with fields.
|
||||
*/
|
||||
class D7Comment extends FieldMigration {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getProcess() {
|
||||
if ($this->init) {
|
||||
return parent::getProcess();
|
||||
}
|
||||
$this->init = TRUE;
|
||||
if (!\Drupal::moduleHandler()->moduleExists('field')) {
|
||||
return parent::getProcess();
|
||||
}
|
||||
$definition['source'] = [
|
||||
'ignore_map' => TRUE,
|
||||
] + $this->getSourceConfiguration();
|
||||
$definition['source']['plugin'] = 'd7_field_instance';
|
||||
$definition['destination']['plugin'] = 'null';
|
||||
$definition['idMap']['plugin'] = 'null';
|
||||
$field_migration = $this->migrationPluginManager->createStubMigration($definition);
|
||||
foreach ($field_migration->getSourcePlugin() as $row) {
|
||||
$field_name = $row->getSourceProperty('field_name');
|
||||
$field_type = $row->getSourceProperty('type');
|
||||
if ($this->fieldPluginManager->hasDefinition($field_type)) {
|
||||
if (!isset($this->fieldPluginCache[$field_type])) {
|
||||
$this->fieldPluginCache[$field_type] = $this->fieldPluginManager->createInstance($field_type, [], $this);
|
||||
}
|
||||
$info = $row->getSource();
|
||||
$this->fieldPluginCache[$field_type]->defineValueProcessPipeline($this, $field_name, $info);
|
||||
}
|
||||
else {
|
||||
$this->setProcessOfProperty($field_name, $field_name);
|
||||
}
|
||||
}
|
||||
return parent::getProcess();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -31,7 +31,7 @@ class CommentVariablePerCommentType extends CommentVariable {
|
||||
$return['comment'] = [
|
||||
'comment_type' => 'comment',
|
||||
'label' => $this->t('Default comments'),
|
||||
'description' => $this->t('Allows commenting on content')
|
||||
'description' => $this->t('Allows commenting on content'),
|
||||
];
|
||||
}
|
||||
else {
|
||||
@@ -39,7 +39,7 @@ class CommentVariablePerCommentType extends CommentVariable {
|
||||
$return['comment_no_subject'] = [
|
||||
'comment_type' => 'comment_no_subject',
|
||||
'label' => $this->t('Comments without subject field'),
|
||||
'description' => $this->t('Allows commenting on content, comments without subject field')
|
||||
'description' => $this->t('Allows commenting on content, comments without subject field'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +40,15 @@ class Comment extends FieldableEntity {
|
||||
$row->setSourceProperty($field, $this->getFieldValues('comment', $field, $cid));
|
||||
}
|
||||
|
||||
// If the comment subject was replaced by a real field using the Drupal 7
|
||||
// Title module, use the field value instead of the comment subject.
|
||||
if ($this->moduleExists('title')) {
|
||||
$subject_field = $row->getSourceProperty('subject_field');
|
||||
if (isset($subject_field[0]['value'])) {
|
||||
$row->setSourceProperty('subject', $subject_field[0]['value']);
|
||||
}
|
||||
}
|
||||
|
||||
return parent::prepareRow($row);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ class UserUid extends ArgumentPluginBase {
|
||||
protected $database;
|
||||
|
||||
/**
|
||||
* Constructs a Drupal\Component\Plugin\PluginBase object.
|
||||
* Constructs a \Drupal\comment\Plugin\views\argument\UserUid object.
|
||||
*
|
||||
* @param array $configuration
|
||||
* A configuration array containing information about the plugin instance.
|
||||
|
||||
@@ -36,7 +36,7 @@ class NodeNewComments extends NumericField {
|
||||
protected $database;
|
||||
|
||||
/**
|
||||
* Constructs a Drupal\Component\Plugin\PluginBase object.
|
||||
* Constructs a \Drupal\comment\Plugin\views\field\NodeNewComments object.
|
||||
*
|
||||
* @param array $configuration
|
||||
* A configuration array containing information about the plugin instance.
|
||||
|
||||
@@ -32,9 +32,9 @@ class StatisticsLastCommentName extends FieldPluginBase {
|
||||
[
|
||||
'field' => 'uid',
|
||||
'operator' => '!=',
|
||||
'value' => '0'
|
||||
]
|
||||
]
|
||||
'value' => '0',
|
||||
],
|
||||
],
|
||||
];
|
||||
$join = \Drupal::service('plugin.manager.views.join')->createInstance('standard', $definition);
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
*
|
||||
* These variables are provided to give context about the parent comment (if
|
||||
* any):
|
||||
* - comment_parent: Full parent comment entity (if any).
|
||||
* - parent_comment: Full parent comment entity (if any).
|
||||
* - parent_author: Equivalent to author for the parent comment.
|
||||
* - parent_created: Equivalent to created for the parent comment.
|
||||
* - parent_changed: Equivalent to changed for the parent comment.
|
||||
|
||||
+1
-1
@@ -5,4 +5,4 @@ package: Testing
|
||||
version: VERSION
|
||||
core: 8.x
|
||||
dependencies:
|
||||
- comment
|
||||
- drupal:comment
|
||||
|
||||
@@ -5,4 +5,4 @@ package: Testing
|
||||
version: VERSION
|
||||
core: 8.x
|
||||
dependencies:
|
||||
- comment
|
||||
- drupal:comment
|
||||
|
||||
@@ -5,5 +5,5 @@ package: Testing
|
||||
version: VERSION
|
||||
core: 8.x
|
||||
dependencies:
|
||||
- comment
|
||||
- views
|
||||
- drupal:comment
|
||||
- drupal:views
|
||||
|
||||
@@ -78,7 +78,7 @@ class CommentAccessTest extends BrowserTestBase {
|
||||
$assert->statusCodeEquals(403);
|
||||
|
||||
// Publishing the node grants access.
|
||||
$this->unpublishedNode->setPublished(TRUE)->save();
|
||||
$this->unpublishedNode->setPublished()->save();
|
||||
$this->drupalGet($comment_url);
|
||||
$assert->statusCodeEquals(200);
|
||||
}
|
||||
@@ -112,7 +112,7 @@ class CommentAccessTest extends BrowserTestBase {
|
||||
$assert->statusCodeEquals(403);
|
||||
|
||||
// Publishing the node grants access.
|
||||
$this->unpublishedNode->setPublished(TRUE)->save();
|
||||
$this->unpublishedNode->setPublished()->save();
|
||||
$this->drupalGet($comment_url);
|
||||
$assert->statusCodeEquals(200);
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ class CommentAdminTest extends CommentTestBase {
|
||||
'comment_body' => $body,
|
||||
'entity_id' => $this->node->id(),
|
||||
'entity_type' => 'node',
|
||||
'field_name' => 'comment'
|
||||
'field_name' => 'comment',
|
||||
]);
|
||||
$this->drupalLogout();
|
||||
|
||||
@@ -145,7 +145,7 @@ class CommentAdminTest extends CommentTestBase {
|
||||
'comment_body' => $body,
|
||||
'entity_id' => $this->node->id(),
|
||||
'entity_type' => 'node',
|
||||
'field_name' => 'comment'
|
||||
'field_name' => 'comment',
|
||||
]);
|
||||
$this->drupalLogout();
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Drupal\Tests\comment\Functional;
|
||||
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Component\Render\FormattableMarkup;
|
||||
use Drupal\user\RoleInterface;
|
||||
|
||||
/**
|
||||
@@ -68,13 +68,13 @@ class CommentBlockTest extends CommentTestBase {
|
||||
// Test the only the 10 latest comments are shown and in the proper order.
|
||||
$this->assertNoText($comments[10]->getSubject(), 'Comment 11 not found in block.');
|
||||
for ($i = 0; $i < 10; $i++) {
|
||||
$this->assertText($comments[$i]->getSubject(), SafeMarkup::format('Comment @number found in block.', ['@number' => 10 - $i]));
|
||||
$this->assertText($comments[$i]->getSubject(), new FormattableMarkup('Comment @number found in block.', ['@number' => 10 - $i]));
|
||||
if ($i > 1) {
|
||||
$previous_position = $position;
|
||||
$position = strpos($this->getRawContent(), $comments[$i]->getSubject());
|
||||
$this->assertTrue($position > $previous_position, SafeMarkup::format('Comment @a appears after comment @b', ['@a' => 10 - $i, '@b' => 11 - $i]));
|
||||
$position = strpos($this->getSession()->getPage()->getContent(), $comments[$i]->getSubject());
|
||||
$this->assertTrue($position > $previous_position, new FormattableMarkup('Comment @a appears after comment @b', ['@a' => 10 - $i, '@b' => 11 - $i]));
|
||||
}
|
||||
$position = strpos($this->getRawContent(), $comments[$i]->getSubject());
|
||||
$position = strpos($this->getSession()->getPage()->getContent(), $comments[$i]->getSubject());
|
||||
}
|
||||
|
||||
// Test that links to comments work when comments are across pages.
|
||||
|
||||
@@ -23,7 +23,7 @@ class CommentCSSTest extends CommentTestBase {
|
||||
// Allow anonymous users to see comments.
|
||||
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, [
|
||||
'access comments',
|
||||
'access content'
|
||||
'access content',
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
+3
-2
@@ -1,14 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\comment\Tests;
|
||||
namespace Drupal\Tests\comment\Functional;
|
||||
|
||||
use Drupal\comment\CommentInterface;
|
||||
use Drupal\comment\CommentManagerInterface;
|
||||
use Drupal\comment\Entity\Comment;
|
||||
use Drupal\comment\Tests\CommentTestTrait;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\system\Tests\Entity\EntityWithUriCacheTagsTestBase;
|
||||
use Drupal\Tests\system\Functional\Entity\EntityWithUriCacheTagsTestBase;
|
||||
use Drupal\user\Entity\Role;
|
||||
use Drupal\user\RoleInterface;
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\comment\Functional;
|
||||
|
||||
use Drupal\comment\Entity\CommentType;
|
||||
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\comment\CommentInterface;
|
||||
use Drupal\Tests\taxonomy\Functional\TaxonomyTestTrait;
|
||||
use Drupal\comment\Entity\Comment;
|
||||
|
||||
/**
|
||||
* Tests comments with other entities.
|
||||
*
|
||||
* @group comment
|
||||
*/
|
||||
class CommentEntityTest extends CommentTestBase {
|
||||
|
||||
/**
|
||||
* Modules to install.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['block', 'comment', 'node', 'history', 'field_ui', 'datetime', 'taxonomy'];
|
||||
|
||||
use TaxonomyTestTrait;
|
||||
|
||||
protected $vocab;
|
||||
protected $commentType;
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->vocab = $this->createVocabulary();
|
||||
$this->commentType = CommentType::create([
|
||||
'id' => 'taxonomy_comment',
|
||||
'label' => 'Taxonomy comment',
|
||||
'description' => '',
|
||||
'target_entity_type_id' => 'taxonomy_term',
|
||||
]);
|
||||
$this->commentType->save();
|
||||
$this->addDefaultCommentField(
|
||||
'taxonomy_term',
|
||||
$this->vocab->id(),
|
||||
'field_comment',
|
||||
CommentItemInterface::OPEN,
|
||||
$this->commentType->id()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests CSS classes on comments.
|
||||
*/
|
||||
public function testEntityChanges() {
|
||||
$this->drupalLogin($this->webUser);
|
||||
// Create a new node.
|
||||
$term = $this->createTerm($this->vocab, ['uid' => $this->webUser->id()]);
|
||||
|
||||
// Add a comment.
|
||||
/** @var \Drupal\comment\CommentInterface $comment */
|
||||
$comment = Comment::create([
|
||||
'entity_id' => $term->id(),
|
||||
'entity_type' => 'taxonomy_term',
|
||||
'field_name' => 'field_comment',
|
||||
'uid' => $this->webUser->id(),
|
||||
'status' => CommentInterface::PUBLISHED,
|
||||
'subject' => $this->randomMachineName(),
|
||||
'language' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
|
||||
'comment_body' => [LanguageInterface::LANGCODE_NOT_SPECIFIED => [$this->randomMachineName()]],
|
||||
]);
|
||||
$comment->save();
|
||||
|
||||
// Request the node with the comment.
|
||||
$this->drupalGet('taxonomy/term/' . $term->id());
|
||||
$settings = $this->getDrupalSettings();
|
||||
$this->assertFalse(isset($settings['ajaxPageState']['libraries']) && in_array('comment/drupal.comment-new-indicator', explode(',', $settings['ajaxPageState']['libraries'])), 'drupal.comment-new-indicator library is present.');
|
||||
$this->assertFalse(isset($settings['history']['lastReadTimestamps']) && in_array($term->id(), array_keys($settings['history']['lastReadTimestamps'])), 'history.lastReadTimestamps is present.');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,7 +5,6 @@ namespace Drupal\Tests\comment\Functional;
|
||||
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;
|
||||
@@ -166,7 +165,7 @@ class CommentInterfaceTest extends CommentTestBase {
|
||||
$this->setCommentsPerPage(50);
|
||||
|
||||
// Attempt to reply to an unpublished comment.
|
||||
$reply_loaded->setPublished(FALSE);
|
||||
$reply_loaded->setUnpublished();
|
||||
$reply_loaded->save();
|
||||
$this->drupalGet('comment/reply/node/' . $this->node->id() . '/comment/' . $reply_loaded->id());
|
||||
$this->assertResponse(403);
|
||||
@@ -311,7 +310,7 @@ class CommentInterfaceTest extends CommentTestBase {
|
||||
$this->assertRaw('<p>' . $comment_text . '</p>');
|
||||
|
||||
// Create a new comment entity view mode.
|
||||
$mode = Unicode::strtolower($this->randomMachineName());
|
||||
$mode = mb_strtolower($this->randomMachineName());
|
||||
EntityViewMode::create([
|
||||
'targetEntityType' => 'comment',
|
||||
'id' => "comment.$mode",
|
||||
|
||||
+19
-34
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\comment\Tests;
|
||||
namespace Drupal\Tests\comment\Functional;
|
||||
|
||||
use Drupal\Component\Serialization\Json;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
@@ -30,34 +30,19 @@ class CommentNewIndicatorTest extends CommentTestBase {
|
||||
* @param array $node_ids
|
||||
* An array of node IDs.
|
||||
*
|
||||
* @return string
|
||||
* The response body.
|
||||
* @return \Psr\Http\Message\ResponseInterface
|
||||
* The HTTP response.
|
||||
*/
|
||||
protected function renderNewCommentsNodeLinks(array $node_ids) {
|
||||
// Build POST values.
|
||||
$post = [];
|
||||
for ($i = 0; $i < count($node_ids); $i++) {
|
||||
$post['node_ids[' . $i . ']'] = $node_ids[$i];
|
||||
}
|
||||
$post['field_name'] = 'comment';
|
||||
$client = $this->getHttpClient();
|
||||
$url = Url::fromRoute('comment.new_comments_node_links');
|
||||
|
||||
// Serialize POST values.
|
||||
foreach ($post as $key => $value) {
|
||||
// Encode according to application/x-www-form-urlencoded
|
||||
// Both names and values needs to be urlencoded, according to
|
||||
// http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4.1
|
||||
$post[$key] = urlencode($key) . '=' . urlencode($value);
|
||||
}
|
||||
$post = implode('&', $post);
|
||||
|
||||
// Perform HTTP request.
|
||||
return $this->curlExec([
|
||||
CURLOPT_URL => \Drupal::url('comment.new_comments_node_links', [], ['absolute' => TRUE]),
|
||||
CURLOPT_POST => TRUE,
|
||||
CURLOPT_POSTFIELDS => $post,
|
||||
CURLOPT_HTTPHEADER => [
|
||||
'Accept: application/json',
|
||||
'Content-Type: application/x-www-form-urlencoded',
|
||||
return $client->request('POST', $this->buildUrl($url), [
|
||||
'cookies' => $this->getSessionCookies(),
|
||||
'http_errors' => FALSE,
|
||||
'form_params' => [
|
||||
'node_ids' => $node_ids,
|
||||
'field_name' => 'comment',
|
||||
],
|
||||
]);
|
||||
}
|
||||
@@ -127,8 +112,8 @@ class CommentNewIndicatorTest extends CommentTestBase {
|
||||
// Pretend the data was not present in drupalSettings, i.e. test the
|
||||
// separate request to the server.
|
||||
$response = $this->renderNewCommentsNodeLinks([$this->node->id()]);
|
||||
$this->assertResponse(200);
|
||||
$json = Json::decode($response);
|
||||
$this->assertSame(200, $response->getStatusCode());
|
||||
$json = Json::decode($response->getBody());
|
||||
$expected = [
|
||||
$this->node->id() => [
|
||||
'new_comment_count' => 1,
|
||||
@@ -138,15 +123,15 @@ class CommentNewIndicatorTest extends CommentTestBase {
|
||||
$this->assertIdentical($expected, $json);
|
||||
|
||||
// Failing to specify node IDs for the endpoint should return a 404.
|
||||
$this->renderNewCommentsNodeLinks([]);
|
||||
$this->assertResponse(404);
|
||||
$response = $this->renderNewCommentsNodeLinks([]);
|
||||
$this->assertSame(404, $response->getStatusCode());
|
||||
|
||||
// Accessing the endpoint as the anonymous user should return a 403.
|
||||
$this->drupalLogout();
|
||||
$this->renderNewCommentsNodeLinks([$this->node->id()]);
|
||||
$this->assertResponse(403);
|
||||
$this->renderNewCommentsNodeLinks([]);
|
||||
$this->assertResponse(403);
|
||||
$response = $this->renderNewCommentsNodeLinks([$this->node->id()]);
|
||||
$this->assertSame(403, $response->getStatusCode());
|
||||
$response = $this->renderNewCommentsNodeLinks([]);
|
||||
$this->assertSame(403, $response->getStatusCode());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -190,7 +190,7 @@ class CommentNonNodeTest extends BrowserTestBase {
|
||||
$regex .= $comment->comment_body->value . '(.*?)';
|
||||
$regex .= '/s';
|
||||
|
||||
return (boolean) preg_match($regex, $this->getRawContent());
|
||||
return (boolean) preg_match($regex, $this->getSession()->getPage()->getContent());
|
||||
}
|
||||
else {
|
||||
return FALSE;
|
||||
@@ -204,7 +204,7 @@ class CommentNonNodeTest extends BrowserTestBase {
|
||||
* Contact info is available.
|
||||
*/
|
||||
public function commentContactInfoAvailable() {
|
||||
return preg_match('/(input).*?(name="name").*?(input).*?(name="mail").*?(input).*?(name="homepage")/s', $this->getRawContent());
|
||||
return preg_match('/(input).*?(name="name").*?(input).*?(name="mail").*?(input).*?(name="homepage")/s', $this->getSession()->getPage()->getContent());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -243,7 +243,7 @@ class CommentNonNodeTest extends BrowserTestBase {
|
||||
*/
|
||||
public function getUnapprovedComment($subject) {
|
||||
$this->drupalGet('admin/content/comment/approval');
|
||||
preg_match('/href="(.*?)#comment-([^"]+)"(.*?)>(' . $subject . ')/', $this->getRawContent(), $match);
|
||||
preg_match('/href="(.*?)#comment-([^"]+)"(.*?)>(' . $subject . ')/', $this->getSession()->getPage()->getContent(), $match);
|
||||
|
||||
return $match[2];
|
||||
}
|
||||
@@ -253,7 +253,7 @@ class CommentNonNodeTest extends BrowserTestBase {
|
||||
*/
|
||||
public function testCommentFunctionality() {
|
||||
$limited_user = $this->drupalCreateUser([
|
||||
'administer entity_test fields'
|
||||
'administer entity_test fields',
|
||||
]);
|
||||
$this->drupalLogin($limited_user);
|
||||
// Test that default field exists.
|
||||
|
||||
+10
-9
@@ -1,9 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\comment\Tests;
|
||||
namespace Drupal\Tests\comment\Functional;
|
||||
|
||||
use Drupal\comment\CommentManagerInterface;
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Component\Render\FormattableMarkup;
|
||||
use Drupal\node\Entity\Node;
|
||||
|
||||
/**
|
||||
@@ -12,6 +12,7 @@ use Drupal\node\Entity\Node;
|
||||
* @group comment
|
||||
*/
|
||||
class CommentPagerTest extends CommentTestBase {
|
||||
|
||||
/**
|
||||
* Confirms comment paging works correctly with flat and threaded comments.
|
||||
*/
|
||||
@@ -216,7 +217,7 @@ class CommentPagerTest extends CommentTestBase {
|
||||
$comment_anchors = $this->xpath('//a[starts-with(@id,"comment-")]');
|
||||
$result_order = [];
|
||||
foreach ($comment_anchors as $anchor) {
|
||||
$result_order[] = substr($anchor['id'], 8);
|
||||
$result_order[] = substr($anchor->getAttribute('id'), 8);
|
||||
}
|
||||
return $this->assertEqual($expected_cids, $result_order, format_string('Comment order: expected @expected, returned @returned.', ['@expected' => implode(',', $expected_cids), '@returned' => implode(',', $result_order)]));
|
||||
}
|
||||
@@ -328,7 +329,7 @@ class CommentPagerTest extends CommentTestBase {
|
||||
'settings' => [
|
||||
'pager_id' => 1,
|
||||
'view_mode' => 'default',
|
||||
]
|
||||
],
|
||||
])
|
||||
->save();
|
||||
|
||||
@@ -338,12 +339,12 @@ class CommentPagerTest extends CommentTestBase {
|
||||
$this->drupalGet('admin/structure/types/manage/article/display');
|
||||
$this->assertNoText(t('Pager ID: @id', ['@id' => 0]), 'No summary for standard pager');
|
||||
$this->assertText(t('Pager ID: @id', ['@id' => 1]));
|
||||
$this->drupalPostAjaxForm(NULL, [], 'comment_settings_edit');
|
||||
$this->drupalPostForm(NULL, [], 'comment_settings_edit');
|
||||
// Change default pager to 2.
|
||||
$this->drupalPostForm(NULL, ['fields[comment][settings_edit_form][settings][pager_id]' => 2], t('Save'));
|
||||
$this->assertText(t('Pager ID: @id', ['@id' => 2]));
|
||||
// Revert the changes.
|
||||
$this->drupalPostAjaxForm(NULL, [], 'comment_settings_edit');
|
||||
$this->drupalPostForm(NULL, [], 'comment_settings_edit');
|
||||
$this->drupalPostForm(NULL, ['fields[comment][settings_edit_form][settings][pager_id]' => 0], t('Save'));
|
||||
$this->assertNoText(t('Pager ID: @id', ['@id' => 0]), 'No summary for standard pager');
|
||||
|
||||
@@ -421,11 +422,11 @@ class CommentPagerTest extends CommentTestBase {
|
||||
$url_before = $this->getUrl();
|
||||
$urls = $this->xpath($xpath, $arguments);
|
||||
if (isset($urls[$index])) {
|
||||
$url_target = $this->getAbsoluteUrl($urls[$index]['href']);
|
||||
$this->pass(SafeMarkup::format('Clicked link %label (@url_target) from @url_before', ['%label' => $xpath, '@url_target' => $url_target, '@url_before' => $url_before]), 'Browser');
|
||||
$url_target = $this->getAbsoluteUrl($urls[$index]->getAttribute('href'));
|
||||
$this->pass(new FormattableMarkup('Clicked link %label (@url_target) from @url_before', ['%label' => $xpath, '@url_target' => $url_target, '@url_before' => $url_before]), 'Browser');
|
||||
return $this->drupalGet($url_target);
|
||||
}
|
||||
$this->fail(SafeMarkup::format('Link %label does not exist on @url_before', ['%label' => $xpath, '@url_before' => $url_before]), 'Browser');
|
||||
$this->fail(new FormattableMarkup('Link %label does not exist on @url_before', ['%label' => $xpath, '@url_before' => $url_before]), 'Browser');
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@@ -336,7 +336,7 @@ abstract class CommentTestBase extends BrowserTestBase {
|
||||
* Contact info is available.
|
||||
*/
|
||||
public function commentContactInfoAvailable() {
|
||||
return preg_match('/(input).*?(name="name").*?(input).*?(name="mail").*?(input).*?(name="homepage")/s', $this->getRawContent());
|
||||
return preg_match('/(input).*?(name="name").*?(input).*?(name="mail").*?(input).*?(name="homepage")/s', $this->getSession()->getPage()->getContent());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -375,7 +375,7 @@ abstract class CommentTestBase extends BrowserTestBase {
|
||||
*/
|
||||
public function getUnapprovedComment($subject) {
|
||||
$this->drupalGet('admin/content/comment/approval');
|
||||
preg_match('/href="(.*?)#comment-([^"]+)"(.*?)>(' . $subject . ')/', $this->getRawContent(), $match);
|
||||
preg_match('/href="(.*?)#comment-([^"]+)"(.*?)>(' . $subject . ')/', $this->getSession()->getPage()->getContent(), $match);
|
||||
|
||||
return $match[2];
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ use Drupal\comment\CommentManagerInterface;
|
||||
* @group comment
|
||||
*/
|
||||
class CommentThreadingTest extends CommentTestBase {
|
||||
|
||||
/**
|
||||
* Tests the comment threading.
|
||||
*/
|
||||
|
||||
@@ -9,6 +9,7 @@ namespace Drupal\Tests\comment\Functional;
|
||||
* @group comment
|
||||
*/
|
||||
class CommentTitleTest extends CommentTestBase {
|
||||
|
||||
/**
|
||||
* Tests markup for comments with empty titles.
|
||||
*/
|
||||
|
||||
@@ -99,7 +99,7 @@ class CommentTranslationUITest extends ContentTranslationUITestBase {
|
||||
$node = $this->drupalCreateNode([
|
||||
'type' => $node_type,
|
||||
$field_name => [
|
||||
['status' => CommentItemInterface::OPEN]
|
||||
['status' => CommentItemInterface::OPEN],
|
||||
],
|
||||
]);
|
||||
$values['entity_id'] = $node->id();
|
||||
|
||||
@@ -52,7 +52,6 @@ class CommentUninstallTest extends BrowserTestBase {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests if uninstallation succeeds if the field has been deleted beforehand.
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\comment\Functional\Hal;
|
||||
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class CommentHalJsonAnonTest extends CommentHalJsonTestBase {
|
||||
|
||||
use AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* Anononymous users cannot edit their own comments.
|
||||
*
|
||||
* @see \Drupal\comment\CommentAccessControlHandler::checkAccess
|
||||
*
|
||||
* Therefore we grant them the 'administer comments' permission for the
|
||||
* purpose of this test. Then they are able to edit their own comments, but
|
||||
* some fields are still not editable, even with that permission.
|
||||
*
|
||||
* @see ::setUpAuthorization
|
||||
*/
|
||||
protected static $patchProtectedFieldNames = [
|
||||
'changed' => NULL,
|
||||
'thread' => NULL,
|
||||
'entity_type' => NULL,
|
||||
'field_name' => NULL,
|
||||
'entity_id' => NULL,
|
||||
];
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\comment\Functional\Hal;
|
||||
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class CommentHalJsonBasicAuthTest extends CommentHalJsonTestBase {
|
||||
|
||||
use BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['basic_auth'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'basic_auth';
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\comment\Functional\Hal;
|
||||
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class CommentHalJsonCookieTest extends CommentHalJsonTestBase {
|
||||
|
||||
use CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'cookie';
|
||||
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\comment\Functional\Hal;
|
||||
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
use Drupal\Tests\comment\Functional\Rest\CommentResourceTestBase;
|
||||
use Drupal\Tests\hal\Functional\EntityResource\HalEntityNormalizationTrait;
|
||||
use Drupal\user\Entity\User;
|
||||
|
||||
abstract class CommentHalJsonTestBase extends CommentResourceTestBase {
|
||||
|
||||
use HalEntityNormalizationTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* The HAL+JSON format causes different PATCH-protected fields. For some
|
||||
* reason, the 'pid' and 'homepage' fields are NOT PATCH-protected, even
|
||||
* though they are for non-HAL+JSON serializations.
|
||||
*
|
||||
* @todo fix in https://www.drupal.org/node/2824271
|
||||
*/
|
||||
protected static $patchProtectedFieldNames = [
|
||||
'status' => "The 'administer comments' permission is required.",
|
||||
'created' => "The 'administer comments' permission is required.",
|
||||
'changed' => NULL,
|
||||
'thread' => NULL,
|
||||
'entity_type' => NULL,
|
||||
'field_name' => NULL,
|
||||
'entity_id' => NULL,
|
||||
'uid' => "The 'administer comments' permission is required.",
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExpectedNormalizedEntity() {
|
||||
$default_normalization = parent::getExpectedNormalizedEntity();
|
||||
|
||||
$normalization = $this->applyHalFieldNormalization($default_normalization);
|
||||
|
||||
// Because \Drupal\comment\Entity\Comment::getOwner() generates an in-memory
|
||||
// User entity without a UUID, we cannot use it.
|
||||
$author = User::load($this->entity->getOwnerId());
|
||||
$commented_entity = EntityTest::load(1);
|
||||
return $normalization + [
|
||||
'_links' => [
|
||||
'self' => [
|
||||
'href' => $this->baseUrl . '/comment/1?_format=hal_json',
|
||||
],
|
||||
'type' => [
|
||||
'href' => $this->baseUrl . '/rest/type/comment/comment',
|
||||
],
|
||||
$this->baseUrl . '/rest/relation/comment/comment/entity_id' => [
|
||||
[
|
||||
'href' => $this->baseUrl . '/entity_test/1?_format=hal_json',
|
||||
],
|
||||
],
|
||||
$this->baseUrl . '/rest/relation/comment/comment/uid' => [
|
||||
[
|
||||
'href' => $this->baseUrl . '/user/' . $author->id() . '?_format=hal_json',
|
||||
'lang' => 'en',
|
||||
],
|
||||
],
|
||||
],
|
||||
'_embedded' => [
|
||||
$this->baseUrl . '/rest/relation/comment/comment/entity_id' => [
|
||||
[
|
||||
'_links' => [
|
||||
'self' => [
|
||||
'href' => $this->baseUrl . '/entity_test/1?_format=hal_json',
|
||||
],
|
||||
'type' => [
|
||||
'href' => $this->baseUrl . '/rest/type/entity_test/bar',
|
||||
],
|
||||
],
|
||||
'uuid' => [
|
||||
['value' => $commented_entity->uuid()],
|
||||
],
|
||||
],
|
||||
],
|
||||
$this->baseUrl . '/rest/relation/comment/comment/uid' => [
|
||||
[
|
||||
'_links' => [
|
||||
'self' => [
|
||||
'href' => $this->baseUrl . '/user/' . $author->id() . '?_format=hal_json',
|
||||
],
|
||||
'type' => [
|
||||
'href' => $this->baseUrl . '/rest/type/user/user',
|
||||
],
|
||||
],
|
||||
'uuid' => [
|
||||
['value' => $author->uuid()],
|
||||
],
|
||||
'lang' => 'en',
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getNormalizedPostEntity() {
|
||||
return parent::getNormalizedPostEntity() + [
|
||||
'_links' => [
|
||||
'type' => [
|
||||
'href' => $this->baseUrl . '/rest/type/comment/comment',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\comment\Functional\Hal;
|
||||
|
||||
use Drupal\Tests\comment\Functional\Rest\CommentTypeResourceTestBase;
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class CommentTypeHalJsonAnonTest extends CommentTypeResourceTestBase {
|
||||
|
||||
use AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\comment\Functional\Hal;
|
||||
|
||||
use Drupal\Tests\comment\Functional\Rest\CommentTypeResourceTestBase;
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class CommentTypeHalJsonBasicAuthTest extends CommentTypeResourceTestBase {
|
||||
|
||||
use BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal', 'basic_auth'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'basic_auth';
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\comment\Functional\Hal;
|
||||
|
||||
use Drupal\Tests\comment\Functional\Rest\CommentTypeResourceTestBase;
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class CommentTypeHalJsonCookieTest extends CommentTypeResourceTestBase {
|
||||
|
||||
use CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'cookie';
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\comment\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class CommentJsonAnonTest extends CommentResourceTestBase {
|
||||
|
||||
use AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* Anononymous users cannot edit their own comments.
|
||||
*
|
||||
* @see \Drupal\comment\CommentAccessControlHandler::checkAccess
|
||||
*
|
||||
* Therefore we grant them the 'administer comments' permission for the
|
||||
* purpose of this test.
|
||||
*
|
||||
* @see ::setUpAuthorization
|
||||
*/
|
||||
protected static $patchProtectedFieldNames = [
|
||||
'pid' => NULL,
|
||||
'entity_id' => NULL,
|
||||
'changed' => NULL,
|
||||
'thread' => NULL,
|
||||
'entity_type' => NULL,
|
||||
'field_name' => NULL,
|
||||
];
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\comment\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class CommentJsonBasicAuthTest extends CommentResourceTestBase {
|
||||
|
||||
use BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['basic_auth'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'basic_auth';
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\comment\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class CommentJsonCookieTest extends CommentResourceTestBase {
|
||||
|
||||
use CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'cookie';
|
||||
|
||||
}
|
||||
@@ -0,0 +1,387 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\comment\Functional\Rest;
|
||||
|
||||
use Drupal\comment\Entity\Comment;
|
||||
use Drupal\comment\Entity\CommentType;
|
||||
use Drupal\comment\Tests\CommentTestTrait;
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
use Drupal\Tests\rest\Functional\BcTimestampNormalizerUnixTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
|
||||
use Drupal\user\Entity\User;
|
||||
use GuzzleHttp\RequestOptions;
|
||||
|
||||
abstract class CommentResourceTestBase extends EntityResourceTestBase {
|
||||
|
||||
use CommentTestTrait, BcTimestampNormalizerUnixTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['comment', 'entity_test'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $entityTypeId = 'comment';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $patchProtectedFieldNames = [
|
||||
'status' => "The 'administer comments' permission is required.",
|
||||
'pid' => NULL,
|
||||
'entity_id' => NULL,
|
||||
'uid' => "The 'administer comments' permission is required.",
|
||||
'name' => "The 'administer comments' permission is required.",
|
||||
'homepage' => "The 'administer comments' permission is required.",
|
||||
'created' => "The 'administer comments' permission is required.",
|
||||
'changed' => NULL,
|
||||
'thread' => NULL,
|
||||
'entity_type' => NULL,
|
||||
'field_name' => NULL,
|
||||
];
|
||||
|
||||
/**
|
||||
* @var \Drupal\comment\CommentInterface
|
||||
*/
|
||||
protected $entity;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUpAuthorization($method) {
|
||||
switch ($method) {
|
||||
case 'GET':
|
||||
$this->grantPermissionsToTestedRole(['access comments', 'view test entity']);
|
||||
break;
|
||||
case 'POST':
|
||||
$this->grantPermissionsToTestedRole(['post comments']);
|
||||
break;
|
||||
case 'PATCH':
|
||||
// Anononymous users are not ever allowed to edit their own comments. To
|
||||
// be able to test PATCHing comments as the anonymous user, the more
|
||||
// permissive 'administer comments' permission must be granted.
|
||||
// @see \Drupal\comment\CommentAccessControlHandler::checkAccess
|
||||
if (static::$auth) {
|
||||
$this->grantPermissionsToTestedRole(['edit own comments']);
|
||||
}
|
||||
else {
|
||||
$this->grantPermissionsToTestedRole(['administer comments']);
|
||||
}
|
||||
break;
|
||||
case 'DELETE':
|
||||
$this->grantPermissionsToTestedRole(['administer comments']);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function createEntity() {
|
||||
// Create a "bar" bundle for the "entity_test" entity type and create.
|
||||
$bundle = 'bar';
|
||||
entity_test_create_bundle($bundle, NULL, 'entity_test');
|
||||
|
||||
// Create a comment field on this bundle.
|
||||
$this->addDefaultCommentField('entity_test', 'bar', 'comment');
|
||||
|
||||
// Create a "Camelids" test entity that the comment will be assigned to.
|
||||
$commented_entity = EntityTest::create([
|
||||
'name' => 'Camelids',
|
||||
'type' => 'bar',
|
||||
]);
|
||||
$commented_entity->save();
|
||||
|
||||
// Create a "Llama" comment.
|
||||
$comment = Comment::create([
|
||||
'comment_body' => [
|
||||
'value' => 'The name "llama" was adopted by European settlers from native Peruvians.',
|
||||
'format' => 'plain_text',
|
||||
],
|
||||
'entity_id' => $commented_entity->id(),
|
||||
'entity_type' => 'entity_test',
|
||||
'field_name' => 'comment',
|
||||
]);
|
||||
$comment->setSubject('Llama')
|
||||
->setOwnerId(static::$auth ? $this->account->id() : 0)
|
||||
->setPublished()
|
||||
->setCreatedTime(123456789)
|
||||
->setChangedTime(123456789);
|
||||
$comment->save();
|
||||
|
||||
return $comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExpectedNormalizedEntity() {
|
||||
$author = User::load($this->entity->getOwnerId());
|
||||
return [
|
||||
'cid' => [
|
||||
['value' => 1],
|
||||
],
|
||||
'uuid' => [
|
||||
['value' => $this->entity->uuid()],
|
||||
],
|
||||
'langcode' => [
|
||||
[
|
||||
'value' => 'en',
|
||||
],
|
||||
],
|
||||
'comment_type' => [
|
||||
[
|
||||
'target_id' => 'comment',
|
||||
'target_type' => 'comment_type',
|
||||
'target_uuid' => CommentType::load('comment')->uuid(),
|
||||
],
|
||||
],
|
||||
'subject' => [
|
||||
[
|
||||
'value' => 'Llama',
|
||||
],
|
||||
],
|
||||
'status' => [
|
||||
[
|
||||
'value' => TRUE,
|
||||
],
|
||||
],
|
||||
'created' => [
|
||||
$this->formatExpectedTimestampItemValues(123456789),
|
||||
],
|
||||
'changed' => [
|
||||
$this->formatExpectedTimestampItemValues($this->entity->getChangedTime()),
|
||||
],
|
||||
'default_langcode' => [
|
||||
[
|
||||
'value' => TRUE,
|
||||
],
|
||||
],
|
||||
'uid' => [
|
||||
[
|
||||
'target_id' => (int) $author->id(),
|
||||
'target_type' => 'user',
|
||||
'target_uuid' => $author->uuid(),
|
||||
'url' => base_path() . 'user/' . $author->id(),
|
||||
],
|
||||
],
|
||||
'pid' => [],
|
||||
'entity_type' => [
|
||||
[
|
||||
'value' => 'entity_test',
|
||||
],
|
||||
],
|
||||
'entity_id' => [
|
||||
[
|
||||
'target_id' => 1,
|
||||
'target_type' => 'entity_test',
|
||||
'target_uuid' => EntityTest::load(1)->uuid(),
|
||||
'url' => base_path() . 'entity_test/1',
|
||||
],
|
||||
],
|
||||
'field_name' => [
|
||||
[
|
||||
'value' => 'comment',
|
||||
],
|
||||
],
|
||||
'name' => [],
|
||||
'homepage' => [],
|
||||
'thread' => [
|
||||
[
|
||||
'value' => '01/',
|
||||
],
|
||||
],
|
||||
'comment_body' => [
|
||||
[
|
||||
'value' => 'The name "llama" was adopted by European settlers from native Peruvians.',
|
||||
'format' => 'plain_text',
|
||||
'processed' => '<p>The name "llama" was adopted by European settlers from native Peruvians.</p>' . "\n",
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getNormalizedPostEntity() {
|
||||
return [
|
||||
'comment_type' => [
|
||||
[
|
||||
'target_id' => 'comment',
|
||||
],
|
||||
],
|
||||
'entity_type' => [
|
||||
[
|
||||
'value' => 'entity_test',
|
||||
],
|
||||
],
|
||||
'entity_id' => [
|
||||
[
|
||||
'target_id' => (int) EntityTest::load(1)->id(),
|
||||
],
|
||||
],
|
||||
'field_name' => [
|
||||
[
|
||||
'value' => 'comment',
|
||||
],
|
||||
],
|
||||
'subject' => [
|
||||
[
|
||||
'value' => 'Dramallama',
|
||||
],
|
||||
],
|
||||
'comment_body' => [
|
||||
[
|
||||
'value' => 'Llamas are awesome.',
|
||||
'format' => 'plain_text',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getNormalizedPatchEntity() {
|
||||
return array_diff_key($this->getNormalizedPostEntity(), ['entity_type' => TRUE, 'entity_id' => TRUE, 'field_name' => TRUE]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExpectedCacheTags() {
|
||||
return Cache::mergeTags(parent::getExpectedCacheTags(), ['config:filter.format.plain_text']);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExpectedCacheContexts() {
|
||||
return Cache::mergeContexts(['languages:language_interface', 'theme'], parent::getExpectedCacheContexts());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests POSTing a comment without critical base fields.
|
||||
*
|
||||
* Tests with the most minimal normalization possible: the one returned by
|
||||
* ::getNormalizedPostEntity().
|
||||
*
|
||||
* But Comment entities have some very special edge cases:
|
||||
* - base fields that are not marked as required in
|
||||
* \Drupal\comment\Entity\Comment::baseFieldDefinitions() yet in fact are
|
||||
* required.
|
||||
* - base fields that are marked as required, but yet can still result in
|
||||
* validation errors other than "missing required field".
|
||||
*/
|
||||
public function testPostDxWithoutCriticalBaseFields() {
|
||||
$this->initAuthentication();
|
||||
$this->provisionEntityResource();
|
||||
$this->setUpAuthorization('POST');
|
||||
|
||||
$url = $this->getEntityResourcePostUrl()->setOption('query', ['_format' => static::$format]);
|
||||
$request_options = [];
|
||||
$request_options[RequestOptions::HEADERS]['Accept'] = static::$mimeType;
|
||||
$request_options[RequestOptions::HEADERS]['Content-Type'] = static::$mimeType;
|
||||
$request_options = array_merge_recursive($request_options, $this->getAuthenticationRequestOptions('POST'));
|
||||
|
||||
// DX: 422 when missing 'entity_type' field.
|
||||
$request_options[RequestOptions::BODY] = $this->serializer->encode(array_diff_key($this->getNormalizedPostEntity(), ['entity_type' => TRUE]), static::$format);
|
||||
$response = $this->request('POST', $url, $request_options);
|
||||
// @todo Uncomment, remove next 3 lines in https://www.drupal.org/node/2820364.
|
||||
$this->assertSame(500, $response->getStatusCode());
|
||||
$this->assertSame(['text/plain; charset=UTF-8'], $response->getHeader('Content-Type'));
|
||||
$this->assertStringStartsWith('The website encountered an unexpected error. Please try again later.</br></br><em class="placeholder">Symfony\Component\HttpKernel\Exception\HttpException</em>: Internal Server Error in <em class="placeholder">Drupal\rest\Plugin\rest\resource\EntityResource->post()</em>', (string) $response->getBody());
|
||||
// $this->assertResourceErrorResponse(422, "Unprocessable Entity: validation failed.\nentity_type: This value should not be null.\n", $response);
|
||||
|
||||
// DX: 422 when missing 'entity_id' field.
|
||||
$request_options[RequestOptions::BODY] = $this->serializer->encode(array_diff_key($this->getNormalizedPostEntity(), ['entity_id' => TRUE]), static::$format);
|
||||
// @todo Remove the try/catch in favor of the two commented lines in
|
||||
// https://www.drupal.org/node/2820364.
|
||||
try {
|
||||
$response = $this->request('POST', $url, $request_options);
|
||||
// This happens on DrupalCI.
|
||||
// $this->assertSame(500, $response->getStatusCode());
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
// This happens on Wim's local machine.
|
||||
// $this->assertSame("Error: Call to a member function get() on null\nDrupal\\comment\\Plugin\\Validation\\Constraint\\CommentNameConstraintValidator->getAnonymousContactDetailsSetting()() (Line: 96)\n", $e->getMessage());
|
||||
}
|
||||
// $response = $this->request('POST', $url, $request_options);
|
||||
// $this->assertResourceErrorResponse(422, "Unprocessable Entity: validation failed.\nentity_type: This value should not be null.\n", $response);
|
||||
|
||||
// DX: 422 when missing 'entity_type' field.
|
||||
$request_options[RequestOptions::BODY] = $this->serializer->encode(array_diff_key($this->getNormalizedPostEntity(), ['field_name' => TRUE]), static::$format);
|
||||
$response = $this->request('POST', $url, $request_options);
|
||||
// @todo Uncomment, remove next 2 lines in https://www.drupal.org/node/2820364.
|
||||
$this->assertSame(500, $response->getStatusCode());
|
||||
$this->assertSame(['text/plain; charset=UTF-8'], $response->getHeader('Content-Type'));
|
||||
// $this->assertResourceErrorResponse(422, "Unprocessable Entity: validation failed.\nfield_name: This value should not be null.\n", $response);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExpectedUnauthorizedAccessMessage($method) {
|
||||
if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) {
|
||||
return parent::getExpectedUnauthorizedAccessMessage($method);
|
||||
}
|
||||
|
||||
switch ($method) {
|
||||
case 'GET';
|
||||
return "The 'access comments' permission is required and the comment must be published.";
|
||||
case 'POST';
|
||||
return "The 'post comments' permission is required.";
|
||||
case 'PATCH';
|
||||
return "The 'edit own comments' permission is required, the user must be the comment author, and the comment must be published.";
|
||||
default:
|
||||
return parent::getExpectedUnauthorizedAccessMessage($method);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests POSTing a comment with and without 'skip comment approval'
|
||||
*/
|
||||
public function testPostSkipCommentApproval() {
|
||||
$this->initAuthentication();
|
||||
$this->provisionEntityResource();
|
||||
$this->setUpAuthorization('POST');
|
||||
|
||||
// Create request.
|
||||
$request_options = [];
|
||||
$request_options[RequestOptions::HEADERS]['Accept'] = static::$mimeType;
|
||||
$request_options[RequestOptions::HEADERS]['Content-Type'] = static::$mimeType;
|
||||
$request_options = array_merge_recursive($request_options, $this->getAuthenticationRequestOptions('POST'));
|
||||
$request_options[RequestOptions::BODY] = $this->serializer->encode($this->getNormalizedPostEntity(), static::$format);
|
||||
|
||||
$url = $this->getEntityResourcePostUrl()->setOption('query', ['_format' => static::$format]);
|
||||
|
||||
// Status should be FALSE when posting as anonymous.
|
||||
$response = $this->request('POST', $url, $request_options);
|
||||
$unserialized = $this->serializer->deserialize((string) $response->getBody(), get_class($this->entity), static::$format);
|
||||
$this->assertResourceResponse(201, FALSE, $response);
|
||||
$this->assertFalse($unserialized->getStatus());
|
||||
|
||||
// Grant anonymous permission to skip comment approval.
|
||||
$this->grantPermissionsToTestedRole(['skip comment approval']);
|
||||
|
||||
// Status should be TRUE when posting as anonymous and skip comment approval.
|
||||
$response = $this->request('POST', $url, $request_options);
|
||||
$unserialized = $this->serializer->deserialize((string) $response->getBody(), get_class($this->entity), static::$format);
|
||||
$this->assertResourceResponse(201, FALSE, $response);
|
||||
$this->assertTrue($unserialized->getStatus());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExpectedUnauthorizedAccessCacheability() {
|
||||
// @see \Drupal\comment\CommentAccessControlHandler::checkAccess()
|
||||
return parent::getExpectedUnauthorizedAccessCacheability()
|
||||
->addCacheTags(['comment:1']);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\comment\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class CommentTypeJsonAnonTest extends CommentTypeResourceTestBase {
|
||||
|
||||
use AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/json';
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\comment\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class CommentTypeJsonBasicAuthTest extends CommentTypeResourceTestBase {
|
||||
|
||||
use BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['basic_auth'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'basic_auth';
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\comment\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class CommentTypeJsonCookieTest extends CommentTypeResourceTestBase {
|
||||
|
||||
use CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'cookie';
|
||||
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\comment\Functional\Rest;
|
||||
|
||||
use Drupal\comment\Entity\CommentType;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
|
||||
|
||||
/**
|
||||
* ResourceTestBase for CommentType entity.
|
||||
*/
|
||||
abstract class CommentTypeResourceTestBase extends EntityResourceTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['node', 'comment'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $entityTypeId = 'comment_type';
|
||||
|
||||
/**
|
||||
* The CommentType entity.
|
||||
*
|
||||
* @var \Drupal\comment\CommentTypeInterface
|
||||
*/
|
||||
protected $entity;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUpAuthorization($method) {
|
||||
$this->grantPermissionsToTestedRole(['administer comment types']);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function createEntity() {
|
||||
// Create a "Camelids" comment type.
|
||||
$camelids = CommentType::create([
|
||||
'id' => 'camelids',
|
||||
'label' => 'Camelids',
|
||||
'description' => 'Camelids are large, strictly herbivorous animals with slender necks and long legs.',
|
||||
'target_entity_type_id' => 'node',
|
||||
]);
|
||||
|
||||
$camelids->save();
|
||||
|
||||
return $camelids;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExpectedNormalizedEntity() {
|
||||
return [
|
||||
'dependencies' => [],
|
||||
'description' => 'Camelids are large, strictly herbivorous animals with slender necks and long legs.',
|
||||
'id' => 'camelids',
|
||||
'label' => 'Camelids',
|
||||
'langcode' => 'en',
|
||||
'status' => TRUE,
|
||||
'target_entity_type_id' => 'node',
|
||||
'uuid' => $this->entity->uuid(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getNormalizedPostEntity() {
|
||||
// @todo Update in https://www.drupal.org/node/2300677.
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\comment\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class CommentTypeXmlAnonTest extends CommentTypeResourceTestBase {
|
||||
|
||||
use AnonResourceTestTrait;
|
||||
use XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'xml';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'text/xml; charset=UTF-8';
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\comment\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class CommentTypeXmlBasicAuthTest extends CommentTypeResourceTestBase {
|
||||
|
||||
use BasicAuthResourceTestTrait;
|
||||
use XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['basic_auth'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'xml';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'text/xml; charset=UTF-8';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'basic_auth';
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\comment\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class CommentTypeXmlCookieTest extends CommentTypeResourceTestBase {
|
||||
|
||||
use CookieResourceTestTrait;
|
||||
use XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'xml';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'text/xml; charset=UTF-8';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'cookie';
|
||||
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\comment\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class CommentXmlAnonTest extends CommentResourceTestBase {
|
||||
|
||||
use AnonResourceTestTrait;
|
||||
use XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'xml';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'text/xml; charset=UTF-8';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* Anononymous users cannot edit their own comments.
|
||||
*
|
||||
* @see \Drupal\comment\CommentAccessControlHandler::checkAccess
|
||||
*
|
||||
* Therefore we grant them the 'administer comments' permission for the
|
||||
* purpose of this test.
|
||||
*
|
||||
* @see ::setUpAuthorization
|
||||
*/
|
||||
protected static $patchProtectedFieldNames = [
|
||||
'pid',
|
||||
'entity_id',
|
||||
'changed',
|
||||
'thread',
|
||||
'entity_type',
|
||||
'field_name',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function testPostDxWithoutCriticalBaseFields() {
|
||||
// Deserialization of the XML format is not supported.
|
||||
$this->markTestSkipped();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function testPostSkipCommentApproval() {
|
||||
// Deserialization of the XML format is not supported.
|
||||
$this->markTestSkipped();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\comment\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class CommentXmlBasicAuthTest extends CommentResourceTestBase {
|
||||
|
||||
use BasicAuthResourceTestTrait;
|
||||
use XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['basic_auth'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'xml';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'text/xml; charset=UTF-8';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'basic_auth';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function testPostDxWithoutCriticalBaseFields() {
|
||||
// Deserialization of the XML format is not supported.
|
||||
$this->markTestSkipped();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function testPostSkipCommentApproval() {
|
||||
// Deserialization of the XML format is not supported.
|
||||
$this->markTestSkipped();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\comment\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class CommentXmlCookieTest extends CommentResourceTestBase {
|
||||
|
||||
use CookieResourceTestTrait;
|
||||
use XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'xml';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'text/xml; charset=UTF-8';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'cookie';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function testPostDxWithoutCriticalBaseFields() {
|
||||
// Deserialization of the XML format is not supported.
|
||||
$this->markTestSkipped();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function testPostSkipCommentApproval() {
|
||||
// Deserialization of the XML format is not supported.
|
||||
$this->markTestSkipped();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,6 +10,7 @@ use Drupal\FunctionalTests\Update\UpdatePathTestBase;
|
||||
* @see comment_post_update_enable_comment_admin_view()
|
||||
*
|
||||
* @group Update
|
||||
* @group legacy
|
||||
*/
|
||||
class CommentAdminViewUpdateTest extends UpdatePathTestBase {
|
||||
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\comment\Functional\Update;
|
||||
|
||||
use Drupal\comment\Entity\Comment;
|
||||
use Drupal\FunctionalTests\Update\UpdatePathTestBase;
|
||||
|
||||
/**
|
||||
* Tests that comment hostname settings are properly updated.
|
||||
*
|
||||
* @group comment
|
||||
* @group legacy
|
||||
*/
|
||||
class CommentHostnameUpdateTest extends UpdatePathTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setDatabaseDumpFiles() {
|
||||
$this->databaseDumpFiles = [
|
||||
__DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8-rc1.bare.standard.php.gz',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests comment_update_8600().
|
||||
*
|
||||
* @see comment_update_8600
|
||||
*/
|
||||
public function testCommentUpdate8600() {
|
||||
/** @var \Drupal\Core\Entity\EntityDefinitionUpdateManagerInterface $manager */
|
||||
$manager = $this->container->get('entity.definition_update_manager');
|
||||
|
||||
/** @var \Drupal\Core\Field\BaseFieldDefinition $definition */
|
||||
$definition = $manager->getFieldStorageDefinition('hostname', 'comment');
|
||||
// Check that 'hostname' base field doesn't have a default value callback.
|
||||
$this->assertNull($definition->getDefaultValueCallback());
|
||||
|
||||
$this->runUpdates();
|
||||
|
||||
$definition = $manager->getFieldStorageDefinition('hostname', 'comment');
|
||||
// Check that 'hostname' base field default value callback was set.
|
||||
$this->assertEquals(Comment::class . '::getDefaultHostname', $definition->getDefaultValueCallback());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,6 +8,7 @@ use Drupal\FunctionalTests\Update\UpdatePathTestBase;
|
||||
* Tests that comment settings are properly updated during database updates.
|
||||
*
|
||||
* @group comment
|
||||
* @group legacy
|
||||
*/
|
||||
class CommentUpdateTest extends UpdatePathTestBase {
|
||||
|
||||
|
||||
@@ -46,14 +46,13 @@ class CommentRestExportTest extends CommentTestBase {
|
||||
$this->drupalLogin($user);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test comment row.
|
||||
*/
|
||||
public function testCommentRestExport() {
|
||||
$this->drupalGet(sprintf('node/%d/comments', $this->nodeUserCommented->id()), ['query' => ['_format' => 'hal_json']]);
|
||||
$this->assertResponse(200);
|
||||
$contents = Json::decode($this->getRawContent());
|
||||
$contents = Json::decode($this->getSession()->getPage()->getContent());
|
||||
$this->assertEqual($contents[0]['subject'], 'How much wood would a woodchuck chuck');
|
||||
$this->assertEqual($contents[1]['subject'], 'A lot, apparently');
|
||||
$this->assertEqual(count($contents), 2);
|
||||
|
||||
@@ -119,7 +119,7 @@ class DefaultViewRecentCommentsTest extends ViewTestBase {
|
||||
$map = [
|
||||
'subject' => 'subject',
|
||||
'cid' => 'cid',
|
||||
'comment_field_data_created' => 'created'
|
||||
'comment_field_data_created' => 'created',
|
||||
];
|
||||
$expected_result = [];
|
||||
foreach (array_values($this->commentsCreated) as $key => $comment) {
|
||||
|
||||
@@ -23,7 +23,6 @@ class WizardTest extends WizardTestBase {
|
||||
*/
|
||||
public static $modules = ['node', 'comment'];
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace Drupal\Tests\comment\Kernel;
|
||||
use Drupal\comment\Entity\Comment;
|
||||
use Drupal\comment\Entity\CommentType;
|
||||
use Drupal\comment\Tests\CommentTestTrait;
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Component\Render\FormattableMarkup;
|
||||
use Drupal\Core\Session\AnonymousUserSession;
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
@@ -202,7 +202,7 @@ class CommentFieldAccessTest extends EntityKernelTestBase {
|
||||
// Generate permutations.
|
||||
$combinations = [
|
||||
'comment' => [$comment1, $comment2, $comment3, $comment4],
|
||||
'user' => [$comment_admin_user, $comment_enabled_user, $comment_no_edit_user, $comment_disabled_user, $anonymous_user]
|
||||
'user' => [$comment_admin_user, $comment_enabled_user, $comment_no_edit_user, $comment_disabled_user, $anonymous_user],
|
||||
];
|
||||
$permutations = $this->generatePermutations($combinations);
|
||||
|
||||
@@ -211,12 +211,12 @@ class CommentFieldAccessTest extends EntityKernelTestBase {
|
||||
foreach ($permutations as $set) {
|
||||
$may_view = $set['comment']->{$field}->access('view', $set['user']);
|
||||
$may_update = $set['comment']->{$field}->access('edit', $set['user']);
|
||||
$this->assertTrue($may_view, SafeMarkup::format('User @user can view field @field on comment @comment', [
|
||||
$this->assertTrue($may_view, new FormattableMarkup('User @user can view field @field on comment @comment', [
|
||||
'@user' => $set['user']->getUsername(),
|
||||
'@comment' => $set['comment']->getSubject(),
|
||||
'@field' => $field,
|
||||
]));
|
||||
$this->assertEqual($may_update, $set['user']->hasPermission('administer comments'), SafeMarkup::format('User @user @state update field @field on comment @comment', [
|
||||
$this->assertEqual($may_update, $set['user']->hasPermission('administer comments'), new FormattableMarkup('User @user @state update field @field on comment @comment', [
|
||||
'@user' => $set['user']->getUsername(),
|
||||
'@state' => $may_update ? 'can' : 'cannot',
|
||||
'@comment' => $set['comment']->getSubject(),
|
||||
@@ -228,7 +228,7 @@ class CommentFieldAccessTest extends EntityKernelTestBase {
|
||||
// Check access to normal field.
|
||||
foreach ($permutations as $set) {
|
||||
$may_update = $set['comment']->access('update', $set['user']) && $set['comment']->subject->access('edit', $set['user']);
|
||||
$this->assertEqual($may_update, $set['user']->hasPermission('administer comments') || ($set['user']->hasPermission('edit own comments') && $set['user']->id() == $set['comment']->getOwnerId()), SafeMarkup::format('User @user @state update field subject on comment @comment', [
|
||||
$this->assertEqual($may_update, $set['user']->hasPermission('administer comments') || ($set['user']->hasPermission('edit own comments') && $set['user']->id() == $set['comment']->getOwnerId()), new FormattableMarkup('User @user @state update field subject on comment @comment', [
|
||||
'@user' => $set['user']->getUsername(),
|
||||
'@state' => $may_update ? 'can' : 'cannot',
|
||||
'@comment' => $set['comment']->getSubject(),
|
||||
@@ -250,13 +250,13 @@ class CommentFieldAccessTest extends EntityKernelTestBase {
|
||||
$view_access = TRUE;
|
||||
$state = 'can';
|
||||
}
|
||||
$this->assertEqual($may_view, $view_access, SafeMarkup::format('User @user @state view field @field on comment @comment', [
|
||||
$this->assertEqual($may_view, $view_access, new FormattableMarkup('User @user @state view field @field on comment @comment', [
|
||||
'@user' => $set['user']->getUsername(),
|
||||
'@comment' => $set['comment']->getSubject(),
|
||||
'@field' => $field,
|
||||
'@state' => $state,
|
||||
]));
|
||||
$this->assertFalse($may_update, SafeMarkup::format('User @user @state update field @field on comment @comment', [
|
||||
$this->assertFalse($may_update, new FormattableMarkup('User @user @state update field @field on comment @comment', [
|
||||
'@user' => $set['user']->getUsername(),
|
||||
'@state' => $may_update ? 'can' : 'cannot',
|
||||
'@comment' => $set['comment']->getSubject(),
|
||||
@@ -271,12 +271,12 @@ class CommentFieldAccessTest extends EntityKernelTestBase {
|
||||
foreach ($permutations as $set) {
|
||||
$may_view = $set['comment']->{$field}->access('view', $set['user']);
|
||||
$may_update = $set['comment']->{$field}->access('edit', $set['user']);
|
||||
$this->assertEqual($may_view, TRUE, SafeMarkup::format('User @user can view field @field on comment @comment', [
|
||||
$this->assertEqual($may_view, TRUE, new FormattableMarkup('User @user can view field @field on comment @comment', [
|
||||
'@user' => $set['user']->getUsername(),
|
||||
'@comment' => $set['comment']->getSubject(),
|
||||
'@field' => $field,
|
||||
]));
|
||||
$this->assertEqual($may_update, $set['user']->hasPermission('post comments') && $set['comment']->isNew(), SafeMarkup::format('User @user @state update field @field on comment @comment', [
|
||||
$this->assertEqual($may_update, $set['user']->hasPermission('post comments') && $set['comment']->isNew(), new FormattableMarkup('User @user @state update field @field on comment @comment', [
|
||||
'@user' => $set['user']->getUsername(),
|
||||
'@state' => $may_update ? 'can' : 'cannot',
|
||||
'@comment' => $set['comment']->getSubject(),
|
||||
@@ -298,7 +298,7 @@ class CommentFieldAccessTest extends EntityKernelTestBase {
|
||||
$set['comment']->isNew() &&
|
||||
$set['user']->hasPermission('post comments') &&
|
||||
$set['comment']->getFieldName() == 'comment_other'
|
||||
), SafeMarkup::format('User @user @state update field @field on comment @comment', [
|
||||
), new FormattableMarkup('User @user @state update field @field on comment @comment', [
|
||||
'@user' => $set['user']->getUsername(),
|
||||
'@state' => $may_update ? 'can' : 'cannot',
|
||||
'@comment' => $set['comment']->getSubject(),
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\comment\Kernel;
|
||||
|
||||
use Drupal\comment\Entity\Comment;
|
||||
use Drupal\comment\Entity\CommentType;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
* Tests the hostname base field.
|
||||
*
|
||||
* @coversDefaultClass \Drupal\comment\Entity\Comment
|
||||
*
|
||||
* @group comment
|
||||
*/
|
||||
class CommentHostnameTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $modules = ['comment', 'entity_test', 'user'];
|
||||
|
||||
/**
|
||||
* Tests hostname default value callback.
|
||||
*
|
||||
* @covers ::getDefaultHostname
|
||||
*/
|
||||
public function testGetDefaultHostname() {
|
||||
// Create a fake request to be used for testing.
|
||||
$request = Request::create('/', 'GET', [], [], [], ['REMOTE_ADDR' => '203.0.113.1']);
|
||||
/** @var \Symfony\Component\HttpFoundation\RequestStack $stack */
|
||||
$stack = $this->container->get('request_stack');
|
||||
$stack->push($request);
|
||||
|
||||
CommentType::create([
|
||||
'id' => 'foo',
|
||||
'target_entity_type_id' => 'entity_test',
|
||||
])->save();
|
||||
$comment = Comment::create(['comment_type' => 'foo']);
|
||||
|
||||
// Check that the hostname was set correctly.
|
||||
$this->assertEquals('203.0.113.1', $comment->getHostname());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,7 +3,6 @@
|
||||
namespace Drupal\Tests\comment\Kernel;
|
||||
|
||||
use Drupal\comment\Entity\CommentType;
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\Core\Database\Database;
|
||||
use Drupal\Core\Entity\Entity\EntityViewDisplay;
|
||||
use Drupal\Core\Entity\Entity\EntityViewMode;
|
||||
@@ -47,7 +46,7 @@ class CommentIntegrationTest extends KernelTestBase {
|
||||
* @see CommentDefaultFormatter::calculateDependencies()
|
||||
*/
|
||||
public function testViewMode() {
|
||||
$mode = Unicode::strtolower($this->randomMachineName());
|
||||
$mode = mb_strtolower($this->randomMachineName());
|
||||
// Create a new comment view mode and a view display entity.
|
||||
EntityViewMode::create([
|
||||
'id' => "comment.$mode",
|
||||
@@ -64,7 +63,7 @@ class CommentIntegrationTest extends KernelTestBase {
|
||||
FieldStorageConfig::create([
|
||||
'entity_type' => 'entity_test',
|
||||
'type' => 'comment',
|
||||
'field_name' => $field_name = Unicode::strtolower($this->randomMachineName()),
|
||||
'field_name' => $field_name = mb_strtolower($this->randomMachineName()),
|
||||
'settings' => [
|
||||
'comment_type' => 'comment',
|
||||
],
|
||||
|
||||
@@ -51,7 +51,7 @@ class CommentValidationTest extends EntityKernelTestBase {
|
||||
'type' => 'comment',
|
||||
'settings' => [
|
||||
'comment_type' => 'comment',
|
||||
]
|
||||
],
|
||||
])->save();
|
||||
|
||||
// Create a page node type.
|
||||
|
||||
@@ -17,7 +17,18 @@ class MigrateCommentTest extends MigrateDrupal7TestBase {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['filter', 'node', 'comment', 'text', 'menu_ui'];
|
||||
public static $modules = [
|
||||
'comment',
|
||||
'datetime',
|
||||
'filter',
|
||||
'image',
|
||||
'link',
|
||||
'menu_ui',
|
||||
'node',
|
||||
'taxonomy',
|
||||
'telephone',
|
||||
'text',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
@@ -40,6 +51,9 @@ class MigrateCommentTest extends MigrateDrupal7TestBase {
|
||||
'd7_comment_field_instance',
|
||||
'd7_comment_entity_display',
|
||||
'd7_comment_entity_form_display',
|
||||
'd7_taxonomy_vocabulary',
|
||||
'd7_field',
|
||||
'd7_field_instance',
|
||||
'd7_comment',
|
||||
]);
|
||||
}
|
||||
@@ -59,10 +73,18 @@ class MigrateCommentTest extends MigrateDrupal7TestBase {
|
||||
$this->assertSame('This is a comment', $comment->comment_body->value);
|
||||
$this->assertSame('filtered_html', $comment->comment_body->format);
|
||||
$this->assertSame('2001:db8:ffff:ffff:ffff:ffff:ffff:ffff', $comment->getHostname());
|
||||
$this->assertSame('1000000', $comment->field_integer->value);
|
||||
|
||||
$node = $comment->getCommentedEntity();
|
||||
$this->assertInstanceOf(NodeInterface::class, $node);
|
||||
$this->assertSame('1', $node->id());
|
||||
|
||||
// Tests that comments that used the Drupal 7 Title module and that have
|
||||
// their subject replaced by a real field are correctly migrated.
|
||||
$comment = Comment::load(2);
|
||||
$this->assertInstanceOf(Comment::class, $comment);
|
||||
$this->assertSame('TNG for the win!', $comment->getSubject());
|
||||
$this->assertSame('TNG is better than DS9.', $comment->comment_body->value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -60,6 +60,16 @@ class CommentTest extends MigrateSqlSourceTestBase {
|
||||
'translate' => '0',
|
||||
],
|
||||
];
|
||||
$tests[0]['source_data']['field_config'] = [
|
||||
[
|
||||
'id' => '1',
|
||||
'translatable' => '0',
|
||||
],
|
||||
[
|
||||
'id' => '2',
|
||||
'translatable' => '1',
|
||||
],
|
||||
];
|
||||
$tests[0]['source_data']['field_config_instance'] = [
|
||||
[
|
||||
'id' => '14',
|
||||
@@ -70,6 +80,15 @@ class CommentTest extends MigrateSqlSourceTestBase {
|
||||
'data' => 'a:0:{}',
|
||||
'deleted' => '0',
|
||||
],
|
||||
[
|
||||
'id' => '15',
|
||||
'field_id' => '2',
|
||||
'field_name' => 'subject_field',
|
||||
'entity_type' => 'comment',
|
||||
'bundle' => 'comment_node_test_content_type',
|
||||
'data' => 'a:0:{}',
|
||||
'deleted' => '0',
|
||||
],
|
||||
];
|
||||
$tests[0]['source_data']['field_data_comment_body'] = [
|
||||
[
|
||||
@@ -84,6 +103,26 @@ class CommentTest extends MigrateSqlSourceTestBase {
|
||||
'comment_body_format' => 'filtered_html',
|
||||
],
|
||||
];
|
||||
$tests[0]['source_data']['field_data_subject_field'] = [
|
||||
[
|
||||
'entity_type' => 'comment',
|
||||
'bundle' => 'comment_node_test_content_type',
|
||||
'deleted' => '0',
|
||||
'entity_id' => '1',
|
||||
'revision_id' => '1',
|
||||
'language' => 'und',
|
||||
'delta' => '0',
|
||||
'subject_field_value' => 'A comment (subject_field)',
|
||||
'subject_field_format' => NULL,
|
||||
],
|
||||
];
|
||||
$tests[0]['source_data']['system'] = [
|
||||
[
|
||||
'name' => 'title',
|
||||
'type' => 'module',
|
||||
'status' => 1,
|
||||
],
|
||||
];
|
||||
|
||||
// The expected results.
|
||||
$tests[0]['expected_data'] = [
|
||||
@@ -92,7 +131,7 @@ class CommentTest extends MigrateSqlSourceTestBase {
|
||||
'pid' => '0',
|
||||
'nid' => '1',
|
||||
'uid' => '1',
|
||||
'subject' => 'A comment',
|
||||
'subject' => 'A comment (subject_field)',
|
||||
'hostname' => '::1',
|
||||
'created' => '1421727536',
|
||||
'changed' => '1421727536',
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace Drupal\Tests\comment\Kernel\Views;
|
||||
|
||||
use Drupal\comment\CommentInterface;
|
||||
use Drupal\comment\CommentManagerInterface;
|
||||
use Drupal\Core\Session\AnonymousUserSession;
|
||||
use Drupal\Core\Url;
|
||||
@@ -84,7 +83,7 @@ class CommentLinksTest extends CommentViewsKernelTestBase {
|
||||
$this->assertEqual(\Drupal::l('Approve', $url), (string) $approve_comment, 'Found a comment approve link for an unapproved comment.');
|
||||
|
||||
// Approve the comment.
|
||||
$comment->setPublished(CommentInterface::PUBLISHED);
|
||||
$comment->setPublished();
|
||||
$comment->save();
|
||||
$view = Views::getView('test_comment');
|
||||
$view->preview();
|
||||
@@ -97,7 +96,7 @@ class CommentLinksTest extends CommentViewsKernelTestBase {
|
||||
// anonymous user.
|
||||
$account_switcher->switchTo(new AnonymousUserSession());
|
||||
// Set the comment as unpublished again.
|
||||
$comment->setPublished(CommentInterface::NOT_PUBLISHED);
|
||||
$comment->setUnpublished();
|
||||
$comment->save();
|
||||
|
||||
$view = Views::getView('test_comment');
|
||||
@@ -168,7 +167,7 @@ class CommentLinksTest extends CommentViewsKernelTestBase {
|
||||
$this->assertFalse((string) $replyto_comment, "I can't reply to an unapproved comment.");
|
||||
|
||||
// Approve the comment.
|
||||
$comment->setPublished(CommentInterface::PUBLISHED);
|
||||
$comment->setPublished();
|
||||
$comment->save();
|
||||
$view = Views::getView('test_comment');
|
||||
$view->preview();
|
||||
|
||||
@@ -118,7 +118,7 @@ class CommentUserNameTest extends ViewsKernelTestBase {
|
||||
'field' => 'name',
|
||||
'id' => 'name',
|
||||
'plugin_id' => 'field',
|
||||
'type' => 'comment_username'
|
||||
'type' => 'comment_username',
|
||||
],
|
||||
'subject' => [
|
||||
'table' => 'comment_field_data',
|
||||
|
||||
@@ -60,7 +60,7 @@ class CommentLinkBuilderTest extends UnitTestCase {
|
||||
protected $timestamp;
|
||||
|
||||
/**
|
||||
* @var \Drupal\comment\CommentLinkBuilderInterface;
|
||||
* @var \Drupal\comment\CommentLinkBuilderInterface
|
||||
*/
|
||||
protected $commentLinkBuilder;
|
||||
|
||||
@@ -310,7 +310,7 @@ class CommentLinkBuilderTest extends UnitTestCase {
|
||||
|
||||
$url = Url::fromRoute('node.view');
|
||||
$node->expects($this->any())
|
||||
->method('urlInfo')
|
||||
->method('toUrl')
|
||||
->willReturn($url);
|
||||
$node->expects($this->any())
|
||||
->method('url')
|
||||
@@ -324,7 +324,9 @@ class CommentLinkBuilderTest extends UnitTestCase {
|
||||
namespace Drupal\comment;
|
||||
|
||||
if (!function_exists('history_read')) {
|
||||
|
||||
function history_read() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -54,6 +54,8 @@ class CommentBulkFormTest extends UnitTestCase {
|
||||
|
||||
$language_manager = $this->getMock('Drupal\Core\Language\LanguageManagerInterface');
|
||||
|
||||
$messenger = $this->getMock('Drupal\Core\Messenger\MessengerInterface');
|
||||
|
||||
$views_data = $this->getMockBuilder('Drupal\views\ViewsData')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
@@ -84,7 +86,7 @@ class CommentBulkFormTest extends UnitTestCase {
|
||||
$definition['title'] = '';
|
||||
$options = [];
|
||||
|
||||
$comment_bulk_form = new CommentBulkForm([], 'comment_bulk_form', $definition, $entity_manager, $language_manager);
|
||||
$comment_bulk_form = new CommentBulkForm([], 'comment_bulk_form', $definition, $entity_manager, $language_manager, $messenger);
|
||||
$comment_bulk_form->init($executable, $display, $options);
|
||||
|
||||
$this->assertAttributeEquals(array_slice($actions, 0, -1, TRUE), 'actions', $comment_bulk_form);
|
||||
|
||||
Reference in New Issue
Block a user