Update Composer, update everything
This commit is contained in:
parent
ea3e94409f
commit
dda5c284b6
19527 changed files with 1135420 additions and 351004 deletions
26
web/core/modules/comment/comment-entity-form.es6.js
Normal file
26
web/core/modules/comment/comment-entity-form.es6.js
Normal file
|
@ -0,0 +1,26 @@
|
|||
/**
|
||||
* @file
|
||||
* Attaches comment behaviors to the entity form.
|
||||
*/
|
||||
|
||||
(function($, Drupal) {
|
||||
/**
|
||||
*
|
||||
* @type {Drupal~behavior}
|
||||
*/
|
||||
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(),
|
||||
),
|
||||
);
|
||||
},
|
||||
};
|
||||
})(jQuery, Drupal);
|
|
@ -1,23 +1,17 @@
|
|||
/**
|
||||
* @file
|
||||
* Attaches comment behaviors to the entity form.
|
||||
*/
|
||||
* DO NOT EDIT THIS FILE.
|
||||
* See the following change record for more information,
|
||||
* https://www.drupal.org/node/2815083
|
||||
* @preserve
|
||||
**/
|
||||
|
||||
(function ($, Drupal) {
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
*
|
||||
* @type {Drupal~behavior}
|
||||
*/
|
||||
Drupal.behaviors.commentFieldsetSummaries = {
|
||||
attach: function (context) {
|
||||
attach: function attach(context) {
|
||||
var $context = $(context);
|
||||
$context.find('fieldset.comment-entity-settings-form').drupalSetSummary(function (context) {
|
||||
return 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;
|
||||
|
@ -184,3 +185,25 @@ function comment_update_8301() {
|
|||
$entity_type->set('entity_keys', $keys);
|
||||
$definition_update_manager->updateEntityType($entity_type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the status field.
|
||||
*/
|
||||
function comment_update_8400() {
|
||||
// The status field was promoted to an entity key in comment_update_8301(),
|
||||
// which makes it NOT NULL in the default SQL storage, which means its storage
|
||||
// definition needs to be updated as well.
|
||||
$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);
|
||||
}
|
||||
|
|
|
@ -25,12 +25,15 @@ use Drupal\field\FieldConfigInterface;
|
|||
use Drupal\field\FieldStorageConfigInterface;
|
||||
use Drupal\node\NodeInterface;
|
||||
use Drupal\user\RoleInterface;
|
||||
use Drupal\user\UserInterface;
|
||||
|
||||
/**
|
||||
* Anonymous posters cannot enter their contact information.
|
||||
*
|
||||
* @deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.0.
|
||||
* Use \Drupal\comment\CommentInterface::ANONYMOUS_MAYNOT_CONTACT instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2831620
|
||||
*/
|
||||
const COMMENT_ANONYMOUS_MAYNOT_CONTACT = 0;
|
||||
|
||||
|
@ -39,6 +42,8 @@ const COMMENT_ANONYMOUS_MAYNOT_CONTACT = 0;
|
|||
*
|
||||
* @deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.0.
|
||||
* Use \Drupal\comment\CommentInterface::ANONYMOUS_MAY_CONTACT instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2831620
|
||||
*/
|
||||
const COMMENT_ANONYMOUS_MAY_CONTACT = 1;
|
||||
|
||||
|
@ -47,6 +52,8 @@ const COMMENT_ANONYMOUS_MAY_CONTACT = 1;
|
|||
*
|
||||
* @deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.0.
|
||||
* Use \Drupal\comment\CommentInterface::ANONYMOUS_MUST_CONTACT instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2831620
|
||||
*/
|
||||
const COMMENT_ANONYMOUS_MUST_CONTACT = 2;
|
||||
|
||||
|
@ -262,7 +269,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().
|
||||
|
@ -285,12 +292,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);
|
||||
|
@ -331,18 +339,6 @@ function comment_form_field_ui_display_overview_form_alter(&$form, FormStateInte
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_form_FORM_ID_alter() for 'field_storage_config_edit_form'.
|
||||
*/
|
||||
function comment_form_field_storage_config_edit_form_alter(&$form, FormStateInterface $form_state) {
|
||||
if ($form_state->getFormObject()->getEntity()->getType() == 'comment') {
|
||||
// We only support posting one comment at the time so it doesn't make sense
|
||||
// to let the site builder choose anything else.
|
||||
$form['cardinality_container']['cardinality']['#default_value'] = 1;
|
||||
$form['cardinality_container']['#access'] = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_entity_storage_load().
|
||||
*
|
||||
|
@ -353,8 +349,7 @@ function comment_entity_storage_load($entities, $entity_type) {
|
|||
if (!\Drupal::entityManager()->getDefinition($entity_type)->entityClassImplements(FieldableEntityInterface::class)) {
|
||||
return;
|
||||
}
|
||||
// @todo Investigate in https://www.drupal.org/node/2527866 why we need that.
|
||||
if (!\Drupal::hasService('comment.manager') || !\Drupal::service('comment.manager')->getFields($entity_type)) {
|
||||
if (!\Drupal::service('comment.manager')->getFields($entity_type)) {
|
||||
// Do not query database when entity has no comment fields.
|
||||
return;
|
||||
}
|
||||
|
@ -524,12 +519,12 @@ function comment_node_search_result(EntityInterface $node) {
|
|||
/**
|
||||
* Implements hook_user_cancel().
|
||||
*/
|
||||
function comment_user_cancel($edit, $account, $method) {
|
||||
function comment_user_cancel($edit, UserInterface $account, $method) {
|
||||
switch ($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;
|
||||
|
@ -565,7 +560,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 = [];
|
||||
|
@ -640,7 +635,7 @@ function template_preprocess_comment(&$variables) {
|
|||
'#theme' => 'username',
|
||||
'#account' => $account,
|
||||
];
|
||||
$variables['author'] = drupal_render($username);
|
||||
$variables['author'] = \Drupal::service('renderer')->render($username);
|
||||
$variables['author_id'] = $comment->getOwnerId();
|
||||
$variables['new_indicator_timestamp'] = $comment->getChangedTime();
|
||||
$variables['created'] = format_date($comment->getCreatedTime());
|
||||
|
@ -686,7 +681,7 @@ function template_preprocess_comment(&$variables) {
|
|||
'#theme' => 'username',
|
||||
'#account' => $account_parent,
|
||||
];
|
||||
$variables['parent_author'] = drupal_render($username);
|
||||
$variables['parent_author'] = \Drupal::service('renderer')->render($username);
|
||||
$variables['parent_created'] = format_date($comment_parent->getCreatedTime());
|
||||
// Avoid calling format_date() twice on the same timestamp.
|
||||
if ($comment_parent->getChangedTime() == $comment_parent->getCreatedTime()) {
|
||||
|
|
38
web/core/modules/comment/comment.post_update.php
Normal file
38
web/core/modules/comment/comment.post_update.php
Normal file
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Post update functions for the comment module.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Config\FileStorage;
|
||||
use Drupal\Core\Config\InstallStorage;
|
||||
|
||||
/**
|
||||
* Enable the comment admin view.
|
||||
*/
|
||||
function comment_post_update_enable_comment_admin_view() {
|
||||
$module_handler = \Drupal::moduleHandler();
|
||||
$entity_type_manager = \Drupal::entityTypeManager();
|
||||
|
||||
// Save the comment delete action to config.
|
||||
$config_install_path = $module_handler->getModule('comment')->getPath() . '/' . InstallStorage::CONFIG_INSTALL_DIRECTORY;
|
||||
$storage = new FileStorage($config_install_path);
|
||||
$entity_type_manager
|
||||
->getStorage('action')
|
||||
->create($storage->read('system.action.comment_delete_action'))
|
||||
->save();
|
||||
|
||||
// Only create if the views module is enabled.
|
||||
if (!$module_handler->moduleExists('views')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Save the comment admin view to config.
|
||||
$optional_install_path = $module_handler->getModule('comment')->getPath() . '/' . InstallStorage::CONFIG_OPTIONAL_DIRECTORY;
|
||||
$storage = new FileStorage($optional_install_path);
|
||||
$entity_type_manager
|
||||
->getStorage('view')
|
||||
->create($storage->read('views.view.comment'))
|
||||
->save();
|
||||
}
|
|
@ -2,7 +2,7 @@ comment.admin:
|
|||
path: '/admin/content/comment'
|
||||
defaults:
|
||||
_title: 'Comments'
|
||||
_controller: '\Drupal\comment\Controller\AdminController::adminPage'
|
||||
_form: '\Drupal\comment\Form\CommentAdminOverview'
|
||||
type: 'new'
|
||||
requirements:
|
||||
_permission: 'administer comments'
|
||||
|
@ -11,7 +11,7 @@ comment.admin_approval:
|
|||
path: '/admin/content/comment/approval'
|
||||
defaults:
|
||||
_title: 'Unapproved comments'
|
||||
_controller: '\Drupal\comment\Controller\AdminController::adminPage'
|
||||
_form: '\Drupal\comment\Form\CommentAdminOverview'
|
||||
type: 'approval'
|
||||
requirements:
|
||||
_permission: 'administer comments'
|
||||
|
@ -54,6 +54,24 @@ entity.comment.delete_form:
|
|||
_entity_access: 'comment.delete'
|
||||
comment: \d+
|
||||
|
||||
comment.multiple_delete_confirm:
|
||||
path: '/admin/content/comment/delete'
|
||||
defaults:
|
||||
_title: 'Delete'
|
||||
_form: '\Drupal\comment\Form\ConfirmDeleteMultiple'
|
||||
entity_type_id: 'comment'
|
||||
requirements:
|
||||
_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}'
|
||||
defaults:
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
module:
|
||||
- comment
|
||||
id: comment_delete_action
|
||||
label: 'Delete comment'
|
||||
type: comment
|
||||
plugin: entity:delete_action:comment
|
||||
configuration: { }
|
|
@ -6,5 +6,5 @@ dependencies:
|
|||
id: comment_publish_action
|
||||
label: 'Publish comment'
|
||||
type: comment
|
||||
plugin: comment_publish_action
|
||||
plugin: entity:publish_action:comment
|
||||
configuration: { }
|
||||
|
|
|
@ -6,5 +6,5 @@ dependencies:
|
|||
id: comment_save_action
|
||||
label: 'Save comment'
|
||||
type: comment
|
||||
plugin: comment_save_action
|
||||
plugin: entity:save_action:comment
|
||||
configuration: { }
|
||||
|
|
|
@ -6,5 +6,5 @@ dependencies:
|
|||
id: comment_unpublish_action
|
||||
label: 'Unpublish comment'
|
||||
type: comment
|
||||
plugin: comment_unpublish_action
|
||||
plugin: entity:unpublish_action:comment
|
||||
configuration: { }
|
||||
|
|
1579
web/core/modules/comment/config/optional/views.view.comment.yml
Normal file
1579
web/core/modules/comment/config/optional/views.view.comment.yml
Normal file
File diff suppressed because it is too large
Load diff
|
@ -15,10 +15,14 @@ field.widget.settings.comment_default:
|
|||
type: mapping
|
||||
label: 'Comment display format settings'
|
||||
|
||||
# @deprecated in Drupal 8.5.x, to be removed before Drupal 9.0.0.
|
||||
# @see https://www.drupal.org/node/2919303
|
||||
action.configuration.comment_publish_action:
|
||||
type: action_configuration_default
|
||||
label: 'Publish comment configuration'
|
||||
|
||||
# @deprecated in Drupal 8.5.x, to be removed before Drupal 9.0.0.
|
||||
# @see https://www.drupal.org/node/2919303
|
||||
action.configuration.comment_save_action:
|
||||
type: action_configuration_default
|
||||
label: 'Save comment configuration'
|
||||
|
@ -34,10 +38,18 @@ action.configuration.comment_unpublish_by_keyword_action:
|
|||
type: string
|
||||
label: 'Keyword'
|
||||
|
||||
# @deprecated in Drupal 8.5.x, to be removed before Drupal 9.0.0.
|
||||
# @see https://www.drupal.org/node/2919303
|
||||
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'
|
||||
|
||||
comment.type.*:
|
||||
type: config_entity
|
||||
label: 'Comment type settings'
|
||||
|
@ -101,7 +113,10 @@ field.field_settings.comment:
|
|||
label: 'Mode'
|
||||
form_location:
|
||||
type: boolean
|
||||
label: ' Allow comment title'
|
||||
label: 'Allow comment title'
|
||||
preview:
|
||||
type: integer
|
||||
label: 'Preview comment'
|
||||
|
||||
field.formatter.settings.comment_permalink:
|
||||
type: field.formatter.settings.string
|
||||
|
|
|
@ -16,6 +16,14 @@ views.field.comment_entity_link:
|
|||
type: boolean
|
||||
label: 'Show teaser-style link'
|
||||
|
||||
views.field.comment_bulk_form:
|
||||
type: views_field_bulk_form
|
||||
label: 'Comment bulk form'
|
||||
|
||||
views.field.commented_entity:
|
||||
type: views.field.field
|
||||
label: 'Commented entity'
|
||||
|
||||
views.field.comment_last_timestamp:
|
||||
type: views.field.date
|
||||
label: 'Last comment date'
|
||||
|
|
25
web/core/modules/comment/js/comment-by-viewer.es6.js
Normal file
25
web/core/modules/comment/js/comment-by-viewer.es6.js
Normal file
|
@ -0,0 +1,25 @@
|
|||
/**
|
||||
* @file
|
||||
* Attaches behaviors for the Comment module's "by-viewer" class.
|
||||
*/
|
||||
|
||||
(function($, Drupal, drupalSettings) {
|
||||
/**
|
||||
* Add 'by-viewer' class to comments written by the current user.
|
||||
*
|
||||
* @type {Drupal~behavior}
|
||||
*/
|
||||
Drupal.behaviors.commentByViewer = {
|
||||
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
|
||||
);
|
||||
})
|
||||
.addClass('by-viewer');
|
||||
},
|
||||
};
|
||||
})(jQuery, Drupal, drupalSettings);
|
|
@ -1,26 +1,17 @@
|
|||
/**
|
||||
* @file
|
||||
* Attaches behaviors for the Comment module's "by-viewer" class.
|
||||
*/
|
||||
* DO NOT EDIT THIS FILE.
|
||||
* See the following change record for more information,
|
||||
* https://www.drupal.org/node/2815083
|
||||
* @preserve
|
||||
**/
|
||||
|
||||
(function ($, Drupal, drupalSettings) {
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Add 'by-viewer' class to comments written by the current user.
|
||||
*
|
||||
* @type {Drupal~behavior}
|
||||
*/
|
||||
Drupal.behaviors.commentByViewer = {
|
||||
attach: function (context) {
|
||||
attach: function attach(context) {
|
||||
var currentUserID = parseInt(drupalSettings.user.uid, 10);
|
||||
$('[data-comment-user-id]')
|
||||
.filter(function () {
|
||||
return parseInt(this.getAttribute('data-comment-user-id'), 10) === currentUserID;
|
||||
})
|
||||
.addClass('by-viewer');
|
||||
$('[data-comment-user-id]').filter(function () {
|
||||
return parseInt(this.getAttribute('data-comment-user-id'), 10) === currentUserID;
|
||||
}).addClass('by-viewer');
|
||||
}
|
||||
};
|
||||
|
||||
})(jQuery, Drupal, drupalSettings);
|
||||
})(jQuery, Drupal, drupalSettings);
|
102
web/core/modules/comment/js/comment-new-indicator.es6.js
Normal file
102
web/core/modules/comment/js/comment-new-indicator.es6.js
Normal file
|
@ -0,0 +1,102 @@
|
|||
/**
|
||||
* @file
|
||||
* Attaches behaviors for the Comment module's "new" indicator.
|
||||
*
|
||||
* May only be loaded for authenticated users, with the History module
|
||||
* installed.
|
||||
*/
|
||||
|
||||
(function($, Drupal, window) {
|
||||
/**
|
||||
* Processes the markup for "new comment" indicators.
|
||||
*
|
||||
* @param {jQuery} $placeholders
|
||||
* The elements that should be processed.
|
||||
*/
|
||||
function processCommentNewIndicators($placeholders) {
|
||||
let isFirstNewComment = true;
|
||||
const newCommentString = Drupal.t('new');
|
||||
let $placeholder;
|
||||
|
||||
$placeholders.each((index, placeholder) => {
|
||||
$placeholder = $(placeholder);
|
||||
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);
|
||||
|
||||
if (timestamp > lastViewTimestamp) {
|
||||
// Turn the placeholder into an actual "new" indicator.
|
||||
const $comment = $(placeholder)
|
||||
.removeClass('hidden')
|
||||
.text(newCommentString)
|
||||
.closest('.js-comment')
|
||||
// Add 'new' class to the comment, so it can be styled.
|
||||
.addClass('new');
|
||||
|
||||
// Insert "new" anchor just before the "comment-<cid>" anchor if
|
||||
// this is the first new comment in the DOM.
|
||||
if (isFirstNewComment) {
|
||||
isFirstNewComment = false;
|
||||
$comment.prev().before('<a id="new" />');
|
||||
// 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,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
|
@ -1,66 +1,15 @@
|
|||
/**
|
||||
* @file
|
||||
* Attaches behaviors for the Comment module's "new" indicator.
|
||||
*
|
||||
* May only be loaded for authenticated users, with the History module
|
||||
* installed.
|
||||
*/
|
||||
* DO NOT EDIT THIS FILE.
|
||||
* See the following change record for more information,
|
||||
* https://www.drupal.org/node/2815083
|
||||
* @preserve
|
||||
**/
|
||||
|
||||
(function ($, Drupal, window) {
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Renders "new" comment indicators wherever necessary.
|
||||
*
|
||||
* @type {Drupal~behavior}
|
||||
*
|
||||
* @prop {Drupal~behaviorAttach} attach
|
||||
* Attaches "new" comment indicators behavior.
|
||||
*/
|
||||
Drupal.behaviors.commentNewIndicator = {
|
||||
attach: function (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.
|
||||
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;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
if ($placeholders.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Fetch the node read timestamps from the server.
|
||||
Drupal.history.fetchTimestamps(nodeIDs, function () {
|
||||
processCommentNewIndicators($placeholders);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Processes the markup for "new comment" indicators.
|
||||
*
|
||||
* @param {jQuery} $placeholders
|
||||
* The elements that should be processed.
|
||||
*/
|
||||
function processCommentNewIndicators($placeholders) {
|
||||
var isFirstNewComment = true;
|
||||
var newCommentString = Drupal.t('new');
|
||||
var $placeholder;
|
||||
var $placeholder = void 0;
|
||||
|
||||
$placeholders.each(function (index, placeholder) {
|
||||
$placeholder = $(placeholder);
|
||||
|
@ -70,21 +19,12 @@
|
|||
var lastViewTimestamp = Drupal.history.getLastRead(nodeID);
|
||||
|
||||
if (timestamp > lastViewTimestamp) {
|
||||
// Turn the placeholder into an actual "new" indicator.
|
||||
var $comment = $(placeholder)
|
||||
.removeClass('hidden')
|
||||
.text(newCommentString)
|
||||
.closest('.js-comment')
|
||||
// Add 'new' class to the comment, so it can be styled.
|
||||
.addClass('new');
|
||||
var $comment = $(placeholder).removeClass('hidden').text(newCommentString).closest('.js-comment').addClass('new');
|
||||
|
||||
// Insert "new" anchor just before the "comment-<cid>" anchor if
|
||||
// this is the first new comment in the DOM.
|
||||
if (isFirstNewComment) {
|
||||
isFirstNewComment = false;
|
||||
$comment.prev().before('<a id="new" />');
|
||||
// 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);
|
||||
}
|
||||
|
@ -93,4 +33,28 @@
|
|||
});
|
||||
}
|
||||
|
||||
})(jQuery, 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);
|
||||
});
|
||||
}
|
||||
};
|
||||
})(jQuery, Drupal, window);
|
195
web/core/modules/comment/js/node-new-comments-link.es6.js
Normal file
195
web/core/modules/comment/js/node-new-comments-link.es6.js
Normal file
|
@ -0,0 +1,195 @@
|
|||
/**
|
||||
* @file
|
||||
* Attaches behaviors for the Comment module's "X new comments" link.
|
||||
*
|
||||
* May only be loaded for authenticated users, with the History module
|
||||
* installed.
|
||||
*/
|
||||
|
||||
(function($, Drupal, drupalSettings) {
|
||||
/**
|
||||
* Hides a "new comment" element.
|
||||
*
|
||||
* @param {jQuery} $placeholder
|
||||
* The placeholder element of the new comment link.
|
||||
*
|
||||
* @return {jQuery}
|
||||
* 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()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a "new comment" element.
|
||||
*
|
||||
* @param {jQuery} $placeholder
|
||||
* The placeholder element of the new comment link.
|
||||
*/
|
||||
function remove($placeholder) {
|
||||
hide($placeholder).remove();
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows a "new comment" element.
|
||||
*
|
||||
* @param {jQuery} $placeholder
|
||||
* The placeholder element of the new comment link.
|
||||
*
|
||||
* @return {jQuery}
|
||||
* 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()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes new comment links and adds appropriate text in relevant cases.
|
||||
*
|
||||
* @param {jQuery} $placeholders
|
||||
* The placeholder elements of the current page.
|
||||
*/
|
||||
function processNodeNewCommentLinks($placeholders) {
|
||||
// Figure out which placeholders need the "x new comments" links.
|
||||
const $placeholdersToUpdate = {};
|
||||
let fieldName = 'comment';
|
||||
let $placeholder;
|
||||
$placeholders.each((index, placeholder) => {
|
||||
$placeholder = $(placeholder);
|
||||
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 lastViewTimestamp = Drupal.history.getLastRead(nodeID);
|
||||
|
||||
// Queue this placeholder's "X new comments" link to be downloaded from
|
||||
// the server.
|
||||
if (timestamp > lastViewTimestamp) {
|
||||
$placeholdersToUpdate[nodeID] = $placeholder;
|
||||
}
|
||||
// No "X new comments" link necessary; remove it from the DOM.
|
||||
else {
|
||||
remove($placeholder);
|
||||
}
|
||||
});
|
||||
|
||||
// Perform an AJAX request to retrieve node view timestamps.
|
||||
const nodeIDs = Object.keys($placeholdersToUpdate);
|
||||
if (nodeIDs.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the "X new comments" links.
|
||||
*
|
||||
* Either use the data embedded in the page or perform an AJAX request to
|
||||
* retrieve the same data.
|
||||
*
|
||||
* @param {object} results
|
||||
* Data about new comment links indexed by nodeID.
|
||||
*/
|
||||
function render(results) {
|
||||
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',
|
||||
),
|
||||
)
|
||||
.removeClass('hidden');
|
||||
show($placeholdersToUpdate[nodeID]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (drupalSettings.comment && drupalSettings.comment.newCommentsLinks) {
|
||||
render(drupalSettings.comment.newCommentsLinks.node[fieldName]);
|
||||
} else {
|
||||
$.ajax({
|
||||
url: Drupal.url('comments/render_new_comments_node_links'),
|
||||
type: 'POST',
|
||||
data: { 'node_ids[]': nodeIDs, field_name: fieldName },
|
||||
dataType: 'json',
|
||||
success: render,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
|
@ -1,120 +1,27 @@
|
|||
/**
|
||||
* @file
|
||||
* Attaches behaviors for the Comment module's "X new comments" link.
|
||||
*
|
||||
* May only be loaded for authenticated users, with the History module
|
||||
* installed.
|
||||
*/
|
||||
* DO NOT EDIT THIS FILE.
|
||||
* See the following change record for more information,
|
||||
* https://www.drupal.org/node/2815083
|
||||
* @preserve
|
||||
**/
|
||||
|
||||
(function ($, Drupal, drupalSettings) {
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Render "X new comments" links wherever necessary.
|
||||
*
|
||||
* @type {Drupal~behavior}
|
||||
*
|
||||
* @prop {Drupal~behaviorAttach} attach
|
||||
* Attaches new comment links behavior.
|
||||
*/
|
||||
Drupal.behaviors.nodeNewCommentsLink = {
|
||||
attach: function (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.
|
||||
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 this placeholder link until it is certain we'll need it.
|
||||
hide($placeholder);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
// 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, function () {
|
||||
processNodeNewCommentLinks($placeholders);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Hides a "new comment" element.
|
||||
*
|
||||
* @param {jQuery} $placeholder
|
||||
* The placeholder element of the new comment link.
|
||||
*
|
||||
* @return {jQuery}
|
||||
* 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.closest('.comment-new-comments').prev().addClass('last').end().hide();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a "new comment" element.
|
||||
*
|
||||
* @param {jQuery} $placeholder
|
||||
* The placeholder element of the new comment link.
|
||||
*/
|
||||
function remove($placeholder) {
|
||||
hide($placeholder).remove();
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows a "new comment" element.
|
||||
*
|
||||
* @param {jQuery} $placeholder
|
||||
* The placeholder element of the new comment link.
|
||||
*
|
||||
* @return {jQuery}
|
||||
* 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.closest('.comment-new-comments').prev().removeClass('last').end().show();
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes new comment links and adds appropriate text in relevant cases.
|
||||
*
|
||||
* @param {jQuery} $placeholders
|
||||
* The placeholder elements of the current page.
|
||||
*/
|
||||
function processNodeNewCommentLinks($placeholders) {
|
||||
// Figure out which placeholders need the "x new comments" links.
|
||||
var $placeholdersToUpdate = {};
|
||||
var fieldName = 'comment';
|
||||
var $placeholder;
|
||||
var $placeholder = void 0;
|
||||
$placeholders.each(function (index, placeholder) {
|
||||
$placeholder = $(placeholder);
|
||||
var timestamp = parseInt($placeholder.attr('data-history-node-last-comment-timestamp'), 10);
|
||||
|
@ -122,56 +29,65 @@
|
|||
var nodeID = $placeholder.closest('[data-history-node-id]').attr('data-history-node-id');
|
||||
var lastViewTimestamp = Drupal.history.getLastRead(nodeID);
|
||||
|
||||
// Queue this placeholder's "X new comments" link to be downloaded from
|
||||
// the server.
|
||||
if (timestamp > lastViewTimestamp) {
|
||||
$placeholdersToUpdate[nodeID] = $placeholder;
|
||||
}
|
||||
// No "X new comments" link necessary; remove it from the DOM.
|
||||
else {
|
||||
remove($placeholder);
|
||||
}
|
||||
} else {
|
||||
remove($placeholder);
|
||||
}
|
||||
});
|
||||
|
||||
// Perform an AJAX request to retrieve node view timestamps.
|
||||
var nodeIDs = Object.keys($placeholdersToUpdate);
|
||||
if (nodeIDs.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the "X new comments" links.
|
||||
*
|
||||
* Either use the data embedded in the page or perform an AJAX request to
|
||||
* retrieve the same data.
|
||||
*
|
||||
* @param {object} results
|
||||
* Data about new comment links indexed by nodeID.
|
||||
*/
|
||||
function render(results) {
|
||||
for (var nodeID in results) {
|
||||
if (results.hasOwnProperty(nodeID) && $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'))
|
||||
.removeClass('hidden');
|
||||
Object.keys(results || {}).forEach(function (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')).removeClass('hidden');
|
||||
show($placeholdersToUpdate[nodeID]);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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',
|
||||
data: {'node_ids[]': nodeIDs, 'field_name': fieldName},
|
||||
data: { 'node_ids[]': nodeIDs, field_name: fieldName },
|
||||
dataType: 'json',
|
||||
success: render
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
})(jQuery, 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);
|
||||
});
|
||||
}
|
||||
};
|
||||
})(jQuery, Drupal, drupalSettings);
|
|
@ -1,44 +0,0 @@
|
|||
id: d6_comment_field_instance
|
||||
label: Comment field instance configuration
|
||||
migration_tags:
|
||||
- Drupal 6
|
||||
source:
|
||||
plugin: d6_comment_variable
|
||||
constants:
|
||||
entity_type: node
|
||||
label: Comments
|
||||
required: true
|
||||
process:
|
||||
entity_type: 'constants/entity_type'
|
||||
label: 'constants/label'
|
||||
required: 'constants/required'
|
||||
field_name:
|
||||
plugin: static_map
|
||||
source: comment_subject_field
|
||||
default_value: comment
|
||||
map:
|
||||
0: comment_no_subject
|
||||
bundle: node_type
|
||||
'default_value/0/status': comment
|
||||
'settings/default_mode':
|
||||
plugin: static_map
|
||||
source: comment_default_mode
|
||||
map:
|
||||
# COMMENT_MODE_FLAT_COLLAPSED --> COMMENT_MODE_FLAT
|
||||
1: 0
|
||||
# COMMENT_MODE_FLAT_EXPANDED --> COMMENT_MODE_FLAT
|
||||
2: 0
|
||||
# COMMENT_MODE_THREADED_COLLAPSED --> COMMENT_MODE_THREADED
|
||||
3: 1
|
||||
# COMMENT_MODE_THREADED_EXPANDED --> COMMENT_MODE_THREADED
|
||||
4: 1
|
||||
'settings/per_page': comment_default_per_page
|
||||
'settings/anonymous': comment_anonymous
|
||||
'settings/form_location': comment_form_location
|
||||
'settings/preview': comment_preview
|
||||
destination:
|
||||
plugin: entity:field_config
|
||||
migration_dependencies:
|
||||
required:
|
||||
- d6_comment_field
|
||||
- d6_node_type
|
|
@ -1,15 +0,0 @@
|
|||
id: d6_comment_type
|
||||
label: Comment type
|
||||
migration_tags:
|
||||
- Drupal 6
|
||||
source:
|
||||
plugin: d6_comment_variable_per_comment_type
|
||||
constants:
|
||||
entity_type: node
|
||||
process:
|
||||
target_entity_type_id: 'constants/entity_type'
|
||||
id: comment_type
|
||||
label: label
|
||||
description: description
|
||||
destination:
|
||||
plugin: entity:comment_type
|
|
@ -1,27 +0,0 @@
|
|||
id: d7_comment_field_instance
|
||||
label: Comment field instance configuration
|
||||
migration_tags:
|
||||
- Drupal 7
|
||||
source:
|
||||
plugin: d7_comment_type
|
||||
constants:
|
||||
entity_type: node
|
||||
label: Comments
|
||||
required: true
|
||||
process:
|
||||
entity_type: 'constants/entity_type'
|
||||
label: 'constants/label'
|
||||
required: 'constants/required'
|
||||
field_name: bundle
|
||||
bundle: node_type
|
||||
'default_value/0/status': 'constants/required'
|
||||
'settings/default_mode': default_mode
|
||||
'settings/per_page': per_page
|
||||
'settings/anonymous': anonymous
|
||||
'settings/form_location': form_location
|
||||
'settings/preview': preview
|
||||
destination:
|
||||
plugin: entity:field_config
|
||||
migration_dependencies:
|
||||
required:
|
||||
- d7_comment_field
|
|
@ -1,17 +0,0 @@
|
|||
id: d7_comment_type
|
||||
label: Comment type
|
||||
migration_tags:
|
||||
- Drupal 7
|
||||
source:
|
||||
plugin: d7_comment_type
|
||||
constants:
|
||||
entity_type: node
|
||||
process:
|
||||
target_entity_type_id: 'constants/entity_type'
|
||||
id: bundle
|
||||
label: label
|
||||
destination:
|
||||
plugin: entity:comment_type
|
||||
migration_dependencies:
|
||||
required:
|
||||
- d7_node_type
|
|
@ -1,7 +1,9 @@
|
|||
id: d6_comment
|
||||
label: Comments
|
||||
audit: true
|
||||
migration_tags:
|
||||
- Drupal 6
|
||||
- Content
|
||||
source:
|
||||
plugin: d6_comment
|
||||
constants:
|
||||
|
@ -14,12 +16,27 @@ process:
|
|||
plugin: migration_lookup
|
||||
migration: d6_comment
|
||||
source: pid
|
||||
entity_id: nid
|
||||
entity_id:
|
||||
-
|
||||
plugin: migration_lookup
|
||||
migration:
|
||||
- d6_node
|
||||
- d6_node_translation
|
||||
source: nid
|
||||
-
|
||||
plugin: skip_on_empty
|
||||
method: row
|
||||
entity_type: 'constants/entity_type'
|
||||
# field_name & comment_type is calculated in
|
||||
# \Drupal\migrate_drupal\Plugin\migrate\source\d6\Comment::prepareRow()
|
||||
field_name: field_name
|
||||
comment_type: comment_type
|
||||
comment_type:
|
||||
-
|
||||
plugin: migration_lookup
|
||||
source: type
|
||||
migration: d6_comment_type
|
||||
-
|
||||
plugin: skip_on_empty
|
||||
method: row
|
||||
langcode: language
|
||||
field_name: '@comment_type'
|
||||
subject: subject
|
||||
uid: uid
|
||||
name: name
|
||||
|
@ -45,3 +62,5 @@ migration_dependencies:
|
|||
- d6_comment_entity_form_display
|
||||
- d6_user
|
||||
- d6_filter_format
|
||||
optional:
|
||||
- d6_node_translation
|
|
@ -2,11 +2,11 @@ id: d6_comment_entity_display
|
|||
label: Comment display configuration
|
||||
migration_tags:
|
||||
- Drupal 6
|
||||
- Configuration
|
||||
source:
|
||||
plugin: d6_comment_variable
|
||||
plugin: d6_node_type
|
||||
constants:
|
||||
entity_type: node
|
||||
field_name: comment
|
||||
view_mode: default
|
||||
options:
|
||||
label: hidden
|
||||
|
@ -14,10 +14,17 @@ source:
|
|||
weight: 20
|
||||
process:
|
||||
entity_type: 'constants/entity_type'
|
||||
field_name: 'constants/field_name'
|
||||
field_name:
|
||||
-
|
||||
plugin: migration_lookup
|
||||
source: type
|
||||
migration: d6_comment_type
|
||||
-
|
||||
plugin: skip_on_empty
|
||||
method: row
|
||||
view_mode: 'constants/view_mode'
|
||||
options: 'constants/options'
|
||||
bundle: node_type
|
||||
bundle: type
|
||||
destination:
|
||||
plugin: component_entity_display
|
||||
migration_dependencies:
|
|
@ -2,21 +2,28 @@ id: d6_comment_entity_form_display
|
|||
label: Comment field form display configuration
|
||||
migration_tags:
|
||||
- Drupal 6
|
||||
- Configuration
|
||||
source:
|
||||
plugin: d6_comment_variable
|
||||
plugin: d6_node_type
|
||||
constants:
|
||||
entity_type: node
|
||||
field_name: comment
|
||||
form_mode: default
|
||||
options:
|
||||
type: comment_default
|
||||
weight: 20
|
||||
process:
|
||||
entity_type: 'constants/entity_type'
|
||||
field_name: 'constants/field_name'
|
||||
field_name:
|
||||
-
|
||||
plugin: migration_lookup
|
||||
source: type
|
||||
migration: d6_comment_type
|
||||
-
|
||||
plugin: skip_on_empty
|
||||
method: row
|
||||
form_mode: 'constants/form_mode'
|
||||
options: 'constants/options'
|
||||
bundle: node_type
|
||||
bundle: type
|
||||
destination:
|
||||
plugin: component_entity_form_display
|
||||
migration_dependencies:
|
|
@ -2,8 +2,9 @@ id: d6_comment_entity_form_display_subject
|
|||
label: Comment subject form display configuration
|
||||
migration_tags:
|
||||
- Drupal 6
|
||||
- Configuration
|
||||
source:
|
||||
plugin: d6_comment_variable_per_comment_type
|
||||
plugin: d6_node_type
|
||||
constants:
|
||||
entity_type: comment
|
||||
field_name: subject
|
||||
|
@ -16,14 +17,23 @@ process:
|
|||
field_name: 'constants/field_name'
|
||||
form_mode: 'constants/form_mode'
|
||||
options: 'constants/options'
|
||||
bundle:
|
||||
-
|
||||
plugin: migration_lookup
|
||||
source: type
|
||||
migration: d6_comment_type
|
||||
-
|
||||
plugin: skip_on_empty
|
||||
method: row
|
||||
hidden:
|
||||
plugin: static_map
|
||||
source: comment_type
|
||||
default_value: false
|
||||
source: comment_subject_field
|
||||
map:
|
||||
comment_no_subject: true # Hide subject field
|
||||
comment: false
|
||||
bundle: comment_type
|
||||
# If comment_subject_field = FALSE, then hidden = TRUE.
|
||||
0: true
|
||||
# If comment_subject_field = TRUE, then hidden = FALSE.
|
||||
1: false
|
||||
default_value: false
|
||||
destination:
|
||||
plugin: component_entity_form_display
|
||||
migration_dependencies:
|
|
@ -2,21 +2,26 @@ id: d6_comment_field
|
|||
label: Comment field configuration
|
||||
migration_tags:
|
||||
- Drupal 6
|
||||
- Configuration
|
||||
source:
|
||||
plugin: d6_comment_variable_per_comment_type
|
||||
plugin: d6_node_type
|
||||
constants:
|
||||
entity_type: node
|
||||
type: comment
|
||||
process:
|
||||
entity_type: 'constants/entity_type'
|
||||
field_name: comment_type
|
||||
field_name:
|
||||
-
|
||||
plugin: migration_lookup
|
||||
source: type
|
||||
migration: d6_comment_type
|
||||
-
|
||||
plugin: skip_on_empty
|
||||
method: row
|
||||
type: 'constants/type'
|
||||
'settings/comment_type': comment_type
|
||||
'settings/comment_type': '@field_name'
|
||||
destination:
|
||||
plugin: entity:field_storage_config
|
||||
dependencies:
|
||||
module:
|
||||
- comment
|
||||
migration_dependencies:
|
||||
required:
|
||||
- d6_comment_type
|
|
@ -0,0 +1,74 @@
|
|||
id: d6_comment_field_instance
|
||||
label: Comment field instance configuration
|
||||
migration_tags:
|
||||
- Drupal 6
|
||||
- Configuration
|
||||
source:
|
||||
plugin: d6_node_type
|
||||
constants:
|
||||
entity_type: node
|
||||
label: Comments
|
||||
required: true
|
||||
process:
|
||||
entity_type: 'constants/entity_type'
|
||||
label: 'constants/label'
|
||||
required: 'constants/required'
|
||||
field_name:
|
||||
-
|
||||
plugin: migration_lookup
|
||||
source: type
|
||||
migration: d6_comment_type
|
||||
-
|
||||
plugin: skip_on_empty
|
||||
method: row
|
||||
bundle: type
|
||||
'default_value/0/status':
|
||||
# We're using static_map instead of default_value otherwise if the source
|
||||
# is 0, the default value of 1 would be used.
|
||||
plugin: static_map
|
||||
source: comment
|
||||
map:
|
||||
0: 0
|
||||
1: 1
|
||||
2: 2
|
||||
default_value: 2
|
||||
'settings/default_mode':
|
||||
plugin: static_map
|
||||
source: comment_default_mode
|
||||
map:
|
||||
# COMMENT_MODE_FLAT_COLLAPSED --> COMMENT_MODE_FLAT
|
||||
1: 0
|
||||
# COMMENT_MODE_FLAT_EXPANDED --> COMMENT_MODE_FLAT
|
||||
2: 0
|
||||
# COMMENT_MODE_THREADED_COLLAPSED --> COMMENT_MODE_THREADED
|
||||
3: 1
|
||||
# COMMENT_MODE_THREADED_EXPANDED --> COMMENT_MODE_THREADED
|
||||
4: 1
|
||||
default_value: 1
|
||||
'settings/per_page':
|
||||
plugin: default_value
|
||||
source: comment_default_per_page
|
||||
default_value: 50
|
||||
'settings/anonymous':
|
||||
plugin: default_value
|
||||
source: comment_anonymous
|
||||
default_value: 0
|
||||
'settings/form_location':
|
||||
plugin: default_value
|
||||
source: comment_form_location
|
||||
default_value: 0
|
||||
'settings/preview':
|
||||
# We're using static_map instead of default_value otherwise if the source
|
||||
# is 0, the default value of 1 would be used.
|
||||
plugin: static_map
|
||||
source: comment_preview
|
||||
map:
|
||||
0: 0
|
||||
1: 1
|
||||
default_value: 1
|
||||
destination:
|
||||
plugin: entity:field_config
|
||||
migration_dependencies:
|
||||
required:
|
||||
- d6_node_type
|
||||
- d6_comment_field
|
34
web/core/modules/comment/migrations/d6_comment_type.yml
Normal file
34
web/core/modules/comment/migrations/d6_comment_type.yml
Normal file
|
@ -0,0 +1,34 @@
|
|||
id: d6_comment_type
|
||||
label: Comment type
|
||||
migration_tags:
|
||||
- Drupal 6
|
||||
- Configuration
|
||||
source:
|
||||
plugin: d6_node_type
|
||||
constants:
|
||||
entity_type: node
|
||||
id_prefix: 'comment_node_'
|
||||
label_suffix: 'comment'
|
||||
process:
|
||||
target_entity_type_id: 'constants/entity_type'
|
||||
id:
|
||||
-
|
||||
plugin: concat
|
||||
source:
|
||||
- 'constants/id_prefix'
|
||||
- type
|
||||
-
|
||||
plugin: static_map
|
||||
bypass: true
|
||||
# The Forum module provides its own comment type (comment_forum), which we
|
||||
# want to reuse if it exists.
|
||||
map:
|
||||
comment_node_forum: comment_forum
|
||||
label:
|
||||
plugin: concat
|
||||
source:
|
||||
- name
|
||||
- 'constants/label_suffix'
|
||||
delimiter: ' '
|
||||
destination:
|
||||
plugin: entity:comment_type
|
|
@ -1,7 +1,10 @@
|
|||
id: d7_comment
|
||||
label: Comments
|
||||
audit: true
|
||||
migration_tags:
|
||||
- Drupal 7
|
||||
- Content
|
||||
class: Drupal\comment\Plugin\migrate\D7Comment
|
||||
source:
|
||||
plugin: d7_comment
|
||||
constants:
|
||||
|
@ -14,10 +17,27 @@ process:
|
|||
plugin: migration_lookup
|
||||
migration: d7_comment
|
||||
source: pid
|
||||
entity_id: nid
|
||||
entity_id:
|
||||
-
|
||||
plugin: migration_lookup
|
||||
migration:
|
||||
- d7_node
|
||||
- d7_node_translation
|
||||
source: nid
|
||||
-
|
||||
plugin: skip_on_empty
|
||||
method: row
|
||||
entity_type: 'constants/entity_type'
|
||||
comment_type: comment_type
|
||||
field_name: comment_type
|
||||
comment_type:
|
||||
-
|
||||
plugin: migration_lookup
|
||||
source: node_type
|
||||
migration: d7_comment_type
|
||||
-
|
||||
plugin: skip_on_empty
|
||||
method: row
|
||||
langcode: language
|
||||
field_name: '@comment_type'
|
||||
subject: subject
|
||||
uid: uid
|
||||
name: name
|
||||
|
@ -35,3 +55,5 @@ migration_dependencies:
|
|||
required:
|
||||
- d7_node
|
||||
- d7_comment_type
|
||||
optional:
|
||||
- d7_node_translation
|
|
@ -2,8 +2,9 @@ id: d7_comment_entity_display
|
|||
label: Comment display configuration
|
||||
migration_tags:
|
||||
- Drupal 7
|
||||
- Configuration
|
||||
source:
|
||||
plugin: d7_comment_type
|
||||
plugin: d7_node_type
|
||||
constants:
|
||||
entity_type: node
|
||||
view_mode: default
|
||||
|
@ -13,10 +14,17 @@ source:
|
|||
weight: 20
|
||||
process:
|
||||
entity_type: 'constants/entity_type'
|
||||
field_name: bundle
|
||||
field_name:
|
||||
-
|
||||
plugin: migration_lookup
|
||||
source: type
|
||||
migration: d7_comment_type
|
||||
-
|
||||
plugin: skip_on_empty
|
||||
method: row
|
||||
view_mode: 'constants/view_mode'
|
||||
options: 'constants/options'
|
||||
bundle: node_type
|
||||
bundle: type
|
||||
destination:
|
||||
plugin: component_entity_display
|
||||
migration_dependencies:
|
|
@ -2,21 +2,28 @@ id: d7_comment_entity_form_display
|
|||
label: Comment field form display configuration
|
||||
migration_tags:
|
||||
- Drupal 7
|
||||
- Configuration
|
||||
source:
|
||||
plugin: d7_comment_type
|
||||
plugin: d7_node_type
|
||||
constants:
|
||||
entity_type: node
|
||||
field_name: comment
|
||||
form_mode: default
|
||||
options:
|
||||
type: comment_default
|
||||
weight: 20
|
||||
process:
|
||||
entity_type: 'constants/entity_type'
|
||||
field_name: 'constants/field_name'
|
||||
field_name:
|
||||
-
|
||||
plugin: migration_lookup
|
||||
source: type
|
||||
migration: d7_comment_type
|
||||
-
|
||||
plugin: skip_on_empty
|
||||
method: row
|
||||
form_mode: 'constants/form_mode'
|
||||
options: 'constants/options'
|
||||
bundle: node_type
|
||||
bundle: type
|
||||
destination:
|
||||
plugin: component_entity_form_display
|
||||
migration_dependencies:
|
|
@ -2,8 +2,9 @@ id: d7_comment_entity_form_display_subject
|
|||
label: Comment subject form display configuration
|
||||
migration_tags:
|
||||
- Drupal 7
|
||||
- Configuration
|
||||
source:
|
||||
plugin: d7_comment_type
|
||||
plugin: d7_node_type
|
||||
constants:
|
||||
entity_type: comment
|
||||
field_name: subject
|
||||
|
@ -16,13 +17,23 @@ process:
|
|||
field_name: 'constants/field_name'
|
||||
form_mode: 'constants/form_mode'
|
||||
options: 'constants/options'
|
||||
bundle:
|
||||
-
|
||||
plugin: migration_lookup
|
||||
source: type
|
||||
migration: d7_comment_type
|
||||
-
|
||||
plugin: skip_on_empty
|
||||
method: row
|
||||
hidden:
|
||||
plugin: static_map
|
||||
source: subject
|
||||
source: comment_subject_field
|
||||
map:
|
||||
# If comment_subject_field = FALSE, then hidden = TRUE.
|
||||
0: true
|
||||
# If comment_subject_field = TRUE, then hidden = FALSE.
|
||||
1: false
|
||||
bundle: bundle
|
||||
default_value: false
|
||||
destination:
|
||||
plugin: component_entity_form_display
|
||||
migration_dependencies:
|
|
@ -2,16 +2,24 @@ id: d7_comment_field
|
|||
label: Comment field configuration
|
||||
migration_tags:
|
||||
- Drupal 7
|
||||
- Configuration
|
||||
source:
|
||||
plugin: d7_comment_type
|
||||
plugin: d7_node_type
|
||||
constants:
|
||||
entity_type: node
|
||||
type: comment
|
||||
process:
|
||||
entity_type: 'constants/entity_type'
|
||||
field_name: bundle
|
||||
field_name:
|
||||
-
|
||||
plugin: migration_lookup
|
||||
source: type
|
||||
migration: d7_comment_type
|
||||
-
|
||||
plugin: skip_on_empty
|
||||
method: row
|
||||
type: 'constants/type'
|
||||
'settings/comment_type': bundle
|
||||
'settings/comment_type': '@field_name'
|
||||
destination:
|
||||
plugin: entity:field_storage_config
|
||||
migration_dependencies:
|
|
@ -0,0 +1,71 @@
|
|||
id: d7_comment_field_instance
|
||||
label: Comment field instance configuration
|
||||
migration_tags:
|
||||
- Drupal 7
|
||||
- Configuration
|
||||
source:
|
||||
plugin: d7_node_type
|
||||
constants:
|
||||
entity_type: node
|
||||
label: Comments
|
||||
required: true
|
||||
process:
|
||||
entity_type: 'constants/entity_type'
|
||||
label: 'constants/label'
|
||||
required: 'constants/required'
|
||||
field_name:
|
||||
-
|
||||
plugin: migration_lookup
|
||||
source: type
|
||||
migration: d7_comment_type
|
||||
-
|
||||
plugin: skip_on_empty
|
||||
method: row
|
||||
bundle: type
|
||||
'default_value/0/status':
|
||||
# We're using static_map instead of default_value otherwise if the source
|
||||
# is 0, the default value of 1 would be used.
|
||||
plugin: static_map
|
||||
source: comment
|
||||
map:
|
||||
0: 0
|
||||
1: 1
|
||||
2: 2
|
||||
default_value: 2
|
||||
'settings/default_mode':
|
||||
# We're using static_map instead of default_value otherwise if the source
|
||||
# is 0, the default value of 1 would be used.
|
||||
plugin: static_map
|
||||
source: comment_default_mode
|
||||
map:
|
||||
0: 0
|
||||
1: 1
|
||||
default_value: 1
|
||||
'settings/per_page':
|
||||
plugin: default_value
|
||||
source: comment_default_per_page
|
||||
default_value: 50
|
||||
'settings/anonymous':
|
||||
plugin: default_value
|
||||
source: comment_anonymous
|
||||
default_value: 0
|
||||
'settings/form_location':
|
||||
plugin: default_value
|
||||
source: comment_form_location
|
||||
default_value: 0
|
||||
'settings/preview':
|
||||
# We're using static_map instead of default_value otherwise if the source
|
||||
# is 0, the default value of 1 would be used.
|
||||
plugin: static_map
|
||||
source: comment_preview
|
||||
map:
|
||||
0: 0
|
||||
1: 1
|
||||
2: 2
|
||||
default_value: 1
|
||||
destination:
|
||||
plugin: entity:field_config
|
||||
migration_dependencies:
|
||||
required:
|
||||
- d7_node_type
|
||||
- d7_comment_field
|
34
web/core/modules/comment/migrations/d7_comment_type.yml
Normal file
34
web/core/modules/comment/migrations/d7_comment_type.yml
Normal file
|
@ -0,0 +1,34 @@
|
|||
id: d7_comment_type
|
||||
label: Comment type
|
||||
migration_tags:
|
||||
- Drupal 7
|
||||
- Configuration
|
||||
source:
|
||||
plugin: d7_node_type
|
||||
constants:
|
||||
entity_type: node
|
||||
id_prefix: 'comment_node_'
|
||||
label_suffix: 'comment'
|
||||
process:
|
||||
target_entity_type_id: 'constants/entity_type'
|
||||
id:
|
||||
-
|
||||
plugin: concat
|
||||
source:
|
||||
- 'constants/id_prefix'
|
||||
- type
|
||||
-
|
||||
plugin: static_map
|
||||
bypass: true
|
||||
# The Forum module provides its own comment type (comment_forum), which we
|
||||
# want to reuse if it exists.
|
||||
map:
|
||||
comment_node_forum: comment_forum
|
||||
label:
|
||||
plugin: concat
|
||||
source:
|
||||
- name
|
||||
- 'constants/label_suffix'
|
||||
delimiter: ' '
|
||||
destination:
|
||||
plugin: entity:comment_type
|
|
@ -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.
|
||||
|
|
|
@ -50,7 +50,7 @@ class CommentFieldItemList extends FieldItemList {
|
|||
return $return_as_object ? $result : $result->isAllowed();
|
||||
}
|
||||
if ($operation === 'view') {
|
||||
// Only users with either post comments or access comments permisison can
|
||||
// Only users with "post comments" or "access comments" permission can
|
||||
// view the field value. The formatter,
|
||||
// Drupal\comment\Plugin\Field\FieldFormatter\CommentDefaultFormatter,
|
||||
// takes care of showing the thread and form based on individual
|
||||
|
|
|
@ -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;
|
||||
|
@ -18,6 +19,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
|||
|
||||
/**
|
||||
* Base handler for comment forms.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class CommentForm extends ContentEntityForm {
|
||||
|
||||
|
@ -35,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
|
||||
|
@ -62,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');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -74,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:
|
||||
|
@ -367,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;
|
||||
}
|
||||
|
@ -392,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);
|
||||
|
|
|
@ -56,8 +56,9 @@ interface CommentInterface extends ContentEntityInterface, EntityChangedInterfac
|
|||
/**
|
||||
* Returns the entity to which the comment is attached.
|
||||
*
|
||||
* @return \Drupal\Core\Entity\FieldableEntityInterface
|
||||
* The entity on which the comment is attached.
|
||||
* @return \Drupal\Core\Entity\FieldableEntityInterface|null
|
||||
* The entity on which the comment is attached or NULL if the comment is an
|
||||
* orphan.
|
||||
*/
|
||||
public function getCommentedEntity();
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace Drupal\comment;
|
||||
|
||||
|
||||
use Drupal\Core\Database\Connection;
|
||||
use Drupal\Core\Entity\FieldableEntityInterface;
|
||||
use Drupal\Core\Entity\EntityChangedInterface;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -12,6 +12,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
|||
|
||||
/**
|
||||
* Base form handler for comment type edit forms.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class CommentTypeForm extends EntityForm {
|
||||
|
||||
|
@ -109,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 {
|
||||
|
@ -158,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']) {
|
||||
|
@ -126,12 +127,15 @@ class CommentViewBuilder extends EntityViewBuilder {
|
|||
$display = $displays[$entity->bundle()];
|
||||
if ($display->getComponent('links')) {
|
||||
$build[$id]['links'] = [
|
||||
'#lazy_builder' => ['comment.lazy_builders:renderLinks', [
|
||||
$entity->id(),
|
||||
$view_mode,
|
||||
$entity->language()->getId(),
|
||||
!empty($entity->in_preview),
|
||||
]],
|
||||
'#lazy_builder' => [
|
||||
'comment.lazy_builders:renderLinks',
|
||||
[
|
||||
$entity->id(),
|
||||
$view_mode,
|
||||
$entity->language()->getId(),
|
||||
!empty($entity->in_preview),
|
||||
],
|
||||
],
|
||||
'#create_placeholder' => TRUE,
|
||||
];
|
||||
}
|
||||
|
@ -140,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.
|
||||
|
|
|
@ -23,6 +23,7 @@ class CommentViewsData extends EntityViewsData {
|
|||
|
||||
$data['comment_field_data']['subject']['title'] = $this->t('Title');
|
||||
$data['comment_field_data']['subject']['help'] = $this->t('The title of the comment.');
|
||||
$data['comment_field_data']['subject']['field']['default_formatter'] = 'comment_permalink';
|
||||
|
||||
$data['comment_field_data']['name']['title'] = $this->t('Author');
|
||||
$data['comment_field_data']['name']['help'] = $this->t("The name of the comment's author. Can be rendered as a link to the author's homepage.");
|
||||
|
@ -168,6 +169,17 @@ class CommentViewsData extends EntityViewsData {
|
|||
],
|
||||
];
|
||||
|
||||
$data['comment_field_data']['entity_id']['field']['id'] = 'commented_entity';
|
||||
unset($data['comment_field_data']['entity_id']['relationship']);
|
||||
|
||||
$data['comment']['comment_bulk_form'] = [
|
||||
'title' => $this->t('Comment operations bulk form'),
|
||||
'help' => $this->t('Add a form element that lets you run operations on multiple comments.'),
|
||||
'field' => [
|
||||
'id' => 'comment_bulk_form',
|
||||
],
|
||||
];
|
||||
|
||||
$data['comment_field_data']['thread']['field'] = [
|
||||
'title' => $this->t('Depth'),
|
||||
'help' => $this->t('Display the depth of the comment if it is threaded.'),
|
||||
|
@ -202,7 +214,7 @@ class CommentViewsData extends EntityViewsData {
|
|||
[
|
||||
'field' => 'entity_type',
|
||||
'value' => $type,
|
||||
'table' => 'comment_field_data'
|
||||
'table' => 'comment_field_data',
|
||||
],
|
||||
],
|
||||
],
|
||||
|
@ -223,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) {
|
||||
|
|
|
@ -1,62 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\comment\Controller;
|
||||
|
||||
use Drupal\Core\Controller\ControllerBase;
|
||||
use Drupal\Core\Form\FormBuilderInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Returns responses for comment module administrative routes.
|
||||
*/
|
||||
class AdminController extends ControllerBase {
|
||||
|
||||
/**
|
||||
* The form builder.
|
||||
*
|
||||
* @var \Drupal\Core\Form\FormBuilderInterface
|
||||
*/
|
||||
protected $formBuilder;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static(
|
||||
$container->get('form_builder')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an AdminController object.
|
||||
*
|
||||
* @param \Drupal\Core\Form\FormBuilderInterface $form_builder
|
||||
* The form builder.
|
||||
*/
|
||||
public function __construct(FormBuilderInterface $form_builder) {
|
||||
$this->formBuilder = $form_builder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Presents an administrative comment listing.
|
||||
*
|
||||
* @param \Symfony\Component\HttpFoundation\Request $request
|
||||
* The request of the page.
|
||||
* @param string $type
|
||||
* The type of the overview form ('approval' or 'new') default to 'new'.
|
||||
*
|
||||
* @return array
|
||||
* Then comment multiple delete confirmation form or the comments overview
|
||||
* administration form.
|
||||
*/
|
||||
public function adminPage(Request $request, $type = 'new') {
|
||||
if ($request->request->get('operation') == 'delete' && $request->request->get('comments')) {
|
||||
return $this->formBuilder->getForm('\Drupal\comment\Form\ConfirmDeleteMultiple', $request);
|
||||
}
|
||||
else {
|
||||
return $this->formBuilder->getForm('\Drupal\comment\Form\CommentAdminOverview', $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());
|
||||
|
@ -279,16 +279,19 @@ class CommentController extends ControllerBase {
|
|||
// Check if the user has the proper permissions.
|
||||
$access = AccessResult::allowedIfHasPermission($account, 'post comments');
|
||||
|
||||
// If commenting is open on the entity.
|
||||
$status = $entity->{$field_name}->status;
|
||||
$access = $access->andIf(AccessResult::allowedIf($status == CommentItemInterface::OPEN)
|
||||
->addCacheableDependency($entity));
|
||||
->addCacheableDependency($entity))
|
||||
// And if user has access to the host entity.
|
||||
->andIf(AccessResult::allowedIf($entity->access('view')));
|
||||
|
||||
// $pid indicates that this is a reply to a comment.
|
||||
if ($pid) {
|
||||
// Check if the user has the proper permissions.
|
||||
$access = $access->andIf(AccessResult::allowedIfHasPermission($account, 'access comments'));
|
||||
|
||||
/// Load the parent comment.
|
||||
// Load the parent comment.
|
||||
$comment = $this->entityManager()->getStorage('comment')->load($pid);
|
||||
// Check if the parent comment is published and belongs to the entity.
|
||||
$access = $access->andIf(AccessResult::allowedIf($comment && $comment->isPublished() && $comment->getCommentedEntityId() == $entity->id()));
|
||||
|
|
|
@ -56,7 +56,9 @@ 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",
|
||||
* },
|
||||
* bundle_entity_type = "comment_type",
|
||||
* field_ui_base_route = "entity.comment_type.edit_form",
|
||||
|
@ -72,6 +74,8 @@ class Comment extends ContentEntityBase implements CommentInterface {
|
|||
|
||||
/**
|
||||
* The thread for which a lock was acquired.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $threadLock = '';
|
||||
|
||||
|
@ -81,14 +85,6 @@ class Comment extends ContentEntityBase implements CommentInterface {
|
|||
public function preSave(EntityStorageInterface $storage) {
|
||||
parent::preSave($storage);
|
||||
|
||||
if (is_null($this->get('status')->value)) {
|
||||
if (\Drupal::currentUser()->hasPermission('skip comment approval')) {
|
||||
$this->setPublished();
|
||||
}
|
||||
else {
|
||||
$this->setUnpublished();
|
||||
}
|
||||
}
|
||||
if ($this->isNew()) {
|
||||
// Add the comment to database. This next section builds the thread field.
|
||||
// @see \Drupal\comment\CommentViewBuilder::buildComponents()
|
||||
|
@ -146,16 +142,15 @@ class Comment extends ContentEntityBase implements CommentInterface {
|
|||
} while (!\Drupal::lock()->acquire($lock_name));
|
||||
$this->threadLock = $lock_name;
|
||||
}
|
||||
// We test the value with '===' because we need to modify anonymous
|
||||
// users as well.
|
||||
if ($this->getOwnerId() === \Drupal::currentUser()->id() && \Drupal::currentUser()->isAuthenticated()) {
|
||||
$this->setAuthorName(\Drupal::currentUser()->getUsername());
|
||||
}
|
||||
$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.
|
||||
// For anonymous users see \Drupal\comment\CommentForm::form() for mail,
|
||||
// and \Drupal\comment\CommentForm::buildEntity() for name setting.
|
||||
if (!$this->getOwner()->isAnonymous()) {
|
||||
$this->set('name', NULL);
|
||||
$this->set('mail', NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -237,6 +232,9 @@ class Comment extends ContentEntityBase implements CommentInterface {
|
|||
|
||||
$fields['langcode']->setDescription(t('The comment language code.'));
|
||||
|
||||
// Set the default value callback for the status field.
|
||||
$fields['status']->setDefaultValueCallback('Drupal\comment\Entity\Comment::getDefaultStatus');
|
||||
|
||||
$fields['pid'] = BaseFieldDefinition::create('entity_reference')
|
||||
->setLabel(t('Parent ID'))
|
||||
->setDescription(t('The parent comment ID if this is a reply to a comment.'))
|
||||
|
@ -289,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'))
|
||||
|
@ -558,4 +557,26 @@ class Comment extends ContentEntityBase implements CommentInterface {
|
|||
return $this->bundle();
|
||||
}
|
||||
|
||||
/**
|
||||
* Default value callback for 'status' base field definition.
|
||||
*
|
||||
* @see ::baseFieldDefinitions()
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if the comment should be published, FALSE otherwise.
|
||||
*/
|
||||
public static function getDefaultStatus() {
|
||||
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",
|
||||
|
|
|
@ -3,26 +3,28 @@
|
|||
namespace Drupal\comment\Form;
|
||||
|
||||
use Drupal\comment\CommentInterface;
|
||||
use Drupal\comment\CommentStorageInterface;
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\Core\Datetime\DateFormatterInterface;
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\Core\Form\FormBase;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\TempStore\PrivateTempStoreFactory;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Provides the comments overview administration form.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class CommentAdminOverview extends FormBase {
|
||||
|
||||
/**
|
||||
* The entity storage.
|
||||
* The entity type manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityManagerInterface
|
||||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
|
||||
*/
|
||||
protected $entityManager;
|
||||
protected $entityTypeManager;
|
||||
|
||||
/**
|
||||
* The comment storage.
|
||||
|
@ -45,23 +47,31 @@ class CommentAdminOverview extends FormBase {
|
|||
*/
|
||||
protected $moduleHandler;
|
||||
|
||||
/**
|
||||
* The tempstore factory.
|
||||
*
|
||||
* @var \Drupal\Core\TempStore\PrivateTempStoreFactory
|
||||
*/
|
||||
protected $tempStoreFactory;
|
||||
|
||||
/**
|
||||
* Creates a CommentAdminOverview form.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
|
||||
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
||||
* The entity manager service.
|
||||
* @param \Drupal\comment\CommentStorageInterface $comment_storage
|
||||
* The comment storage.
|
||||
* @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter
|
||||
* The date formatter service.
|
||||
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
|
||||
* The module handler.
|
||||
* @param \Drupal\Core\TempStore\PrivateTempStoreFactory $temp_store_factory
|
||||
* The tempstore factory.
|
||||
*/
|
||||
public function __construct(EntityManagerInterface $entity_manager, CommentStorageInterface $comment_storage, DateFormatterInterface $date_formatter, ModuleHandlerInterface $module_handler) {
|
||||
$this->entityManager = $entity_manager;
|
||||
$this->commentStorage = $comment_storage;
|
||||
public function __construct(EntityTypeManagerInterface $entity_type_manager, DateFormatterInterface $date_formatter, ModuleHandlerInterface $module_handler, PrivateTempStoreFactory $temp_store_factory) {
|
||||
$this->entityTypeManager = $entity_type_manager;
|
||||
$this->commentStorage = $entity_type_manager->getStorage('comment');
|
||||
$this->dateFormatter = $date_formatter;
|
||||
$this->moduleHandler = $module_handler;
|
||||
$this->tempStoreFactory = $temp_store_factory;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -69,10 +79,10 @@ class CommentAdminOverview extends FormBase {
|
|||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static(
|
||||
$container->get('entity.manager'),
|
||||
$container->get('entity.manager')->getStorage('comment'),
|
||||
$container->get('entity_type.manager'),
|
||||
$container->get('date.formatter'),
|
||||
$container->get('module_handler')
|
||||
$container->get('module_handler'),
|
||||
$container->get('tempstore.private')
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -171,7 +181,9 @@ class CommentAdminOverview extends FormBase {
|
|||
}
|
||||
|
||||
foreach ($commented_entity_ids as $entity_type => $ids) {
|
||||
$commented_entities[$entity_type] = $this->entityManager->getStorage($entity_type)->loadMultiple($ids);
|
||||
$commented_entities[$entity_type] = $this->entityTypeManager
|
||||
->getStorage($entity_type)
|
||||
->loadMultiple($ids);
|
||||
}
|
||||
|
||||
foreach ($comments as $comment) {
|
||||
|
@ -255,23 +267,33 @@ class CommentAdminOverview extends FormBase {
|
|||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||
$operation = $form_state->getValue('operation');
|
||||
$cids = $form_state->getValue('comments');
|
||||
|
||||
foreach ($cids as $cid) {
|
||||
// Delete operation handled in \Drupal\comment\Form\ConfirmDeleteMultiple
|
||||
// see \Drupal\comment\Controller\AdminController::adminPage().
|
||||
if ($operation == 'unpublish') {
|
||||
$comment = $this->commentStorage->load($cid);
|
||||
$comment->setPublished(FALSE);
|
||||
$comment->save();
|
||||
}
|
||||
elseif ($operation == 'publish') {
|
||||
$comment = $this->commentStorage->load($cid);
|
||||
$comment->setPublished(TRUE);
|
||||
/** @var \Drupal\comment\CommentInterface[] $comments */
|
||||
$comments = $this->commentStorage->loadMultiple($cids);
|
||||
if ($operation != 'delete') {
|
||||
foreach ($comments as $comment) {
|
||||
if ($operation == 'unpublish') {
|
||||
$comment->setUnpublished();
|
||||
}
|
||||
elseif ($operation == 'publish') {
|
||||
$comment->setPublished();
|
||||
}
|
||||
$comment->save();
|
||||
}
|
||||
$this->messenger()->addStatus($this->t('The update has been performed.'));
|
||||
$form_state->setRedirect('comment.admin');
|
||||
}
|
||||
else {
|
||||
$info = [];
|
||||
/** @var \Drupal\comment\CommentInterface $comment */
|
||||
foreach ($comments as $comment) {
|
||||
$langcode = $comment->language()->getId();
|
||||
$info[$comment->id()][$langcode] = $langcode;
|
||||
}
|
||||
$this->tempStoreFactory
|
||||
->get('entity_delete_multiple_confirm')
|
||||
->set($this->currentUser()->id() . ':comment', $info);
|
||||
$form_state->setRedirect('entity.comment.delete_multiple_form');
|
||||
}
|
||||
drupal_set_message($this->t('The update has been performed.'));
|
||||
$form_state->setRedirect('comment.admin');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,6 +12,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
|||
|
||||
/**
|
||||
* Provides a confirmation form for deleting a comment type entity.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class CommentTypeDeleteForm extends EntityDeleteForm {
|
||||
|
||||
|
|
|
@ -2,63 +2,21 @@
|
|||
|
||||
namespace Drupal\comment\Form;
|
||||
|
||||
use Drupal\comment\CommentStorageInterface;
|
||||
use Drupal\Component\Utility\Html;
|
||||
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 comment storage.
|
||||
*
|
||||
* @var \Drupal\comment\CommentStorageInterface
|
||||
*/
|
||||
protected $commentStorage;
|
||||
|
||||
/**
|
||||
* An array of comments to be deleted.
|
||||
*
|
||||
* @var \Drupal\comment\CommentInterface[]
|
||||
*/
|
||||
protected $comments;
|
||||
|
||||
/**
|
||||
* Creates an new ConfirmDeleteMultiple form.
|
||||
*
|
||||
* @param \Drupal\comment\CommentStorageInterface $comment_storage
|
||||
* The comment storage.
|
||||
*/
|
||||
public function __construct(CommentStorageInterface $comment_storage) {
|
||||
$this->commentStorage = $comment_storage;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static(
|
||||
$container->get('entity.manager')->getStorage('comment')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFormId() {
|
||||
return 'comment_multiple_delete_confirm';
|
||||
}
|
||||
class ConfirmDeleteMultiple extends EntityDeleteMultipleForm {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getQuestion() {
|
||||
return $this->t('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?');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -71,55 +29,15 @@ class ConfirmDeleteMultiple extends ConfirmFormBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getConfirmText() {
|
||||
return $this->t('Delete comments');
|
||||
protected function getDeletedMessage($count) {
|
||||
return $this->formatPlural($count, 'Deleted @count comment.', 'Deleted @count comments.');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$edit = $form_state->getUserInput();
|
||||
|
||||
$form['comments'] = [
|
||||
'#prefix' => '<ul>',
|
||||
'#suffix' => '</ul>',
|
||||
'#tree' => TRUE,
|
||||
];
|
||||
// array_filter() returns only elements with actual values.
|
||||
$comment_counter = 0;
|
||||
$this->comments = $this->commentStorage->loadMultiple(array_keys(array_filter($edit['comments'])));
|
||||
foreach ($this->comments as $comment) {
|
||||
$cid = $comment->id();
|
||||
$form['comments'][$cid] = [
|
||||
'#type' => 'hidden',
|
||||
'#value' => $cid,
|
||||
'#prefix' => '<li>',
|
||||
'#suffix' => Html::escape($comment->label()) . '</li>'
|
||||
];
|
||||
$comment_counter++;
|
||||
}
|
||||
$form['operation'] = ['#type' => 'hidden', '#value' => 'delete'];
|
||||
|
||||
if (!$comment_counter) {
|
||||
drupal_set_message($this->t('There do not appear to be any comments to delete, or your selected comment was deleted by another administrator.'));
|
||||
$form_state->setRedirect('comment.admin');
|
||||
}
|
||||
|
||||
return parent::buildForm($form, $form_state);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||
if ($form_state->getValue('confirm')) {
|
||||
$this->commentStorage->delete($this->comments);
|
||||
$count = count($form_state->getValue('comments'));
|
||||
$this->logger('comment')->notice('Deleted @count comments.', ['@count' => $count]);
|
||||
drupal_set_message($this->formatPlural($count, 'Deleted 1 comment.', 'Deleted @count comments.'));
|
||||
}
|
||||
$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.");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@ use Drupal\Core\Entity\ContentEntityDeleteForm;
|
|||
|
||||
/**
|
||||
* Provides the comment delete confirmation form.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class DeleteForm extends ContentEntityDeleteForm {
|
||||
|
||||
|
|
34
web/core/modules/comment/src/Plugin/Action/DeleteComment.php
Normal file
34
web/core/modules/comment/src/Plugin/Action/DeleteComment.php
Normal file
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\comment\Plugin\Action;
|
||||
|
||||
use Drupal\Core\Action\Plugin\Action\DeleteAction;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\Core\TempStore\PrivateTempStoreFactory;
|
||||
|
||||
/**
|
||||
* 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")
|
||||
* )
|
||||
*/
|
||||
class DeleteComment extends DeleteAction {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
|
@ -2,37 +2,32 @@
|
|||
|
||||
namespace Drupal\comment\Plugin\Action;
|
||||
|
||||
use Drupal\Core\Action\ActionBase;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\Core\Action\Plugin\Action\PublishAction;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
|
||||
/**
|
||||
* Publishes a comment.
|
||||
*
|
||||
* @deprecated in Drupal 8.5.x, to be removed before Drupal 9.0.0.
|
||||
* Use \Drupal\Core\Action\Plugin\Action\PublishAction instead.
|
||||
*
|
||||
* @see \Drupal\Core\Action\Plugin\Action\PublishAction
|
||||
* @see https://www.drupal.org/node/2919303
|
||||
*
|
||||
* @Action(
|
||||
* id = "comment_publish_action",
|
||||
* label = @Translation("Publish comment"),
|
||||
* type = "comment"
|
||||
* )
|
||||
*/
|
||||
class PublishComment extends ActionBase {
|
||||
class PublishComment extends PublishAction {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function execute($comment = NULL) {
|
||||
$comment->setPublished(TRUE);
|
||||
$comment->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
|
||||
/** @var \Drupal\comment\CommentInterface $object */
|
||||
$result = $object->status->access('edit', $account, TRUE)
|
||||
->andIf($object->access('update', $account, TRUE));
|
||||
|
||||
return $return_as_object ? $result : $result->isAllowed();
|
||||
public function __construct($configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition, $entity_type_manager);
|
||||
@trigger_error(__NAMESPACE__ . '\PublishComment is deprecated in Drupal 8.5.x, will be removed before Drupal 9.0.0. Use \Drupal\Core\Action\Plugin\Action\PublishAction instead. See https://www.drupal.org/node/2919303.', E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,33 +2,33 @@
|
|||
|
||||
namespace Drupal\comment\Plugin\Action;
|
||||
|
||||
use Drupal\Core\Action\ActionBase;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\Component\Datetime\TimeInterface;
|
||||
use Drupal\Core\Action\Plugin\Action\SaveAction;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
|
||||
/**
|
||||
* Saves a comment.
|
||||
*
|
||||
* @deprecated in Drupal 8.5.x, to be removed before Drupal 9.0.0.
|
||||
* Use \Drupal\Core\Action\Plugin\Action\SaveAction instead.
|
||||
*
|
||||
* @see \Drupal\Core\Action\Plugin\Action\SaveAction
|
||||
* @see https://www.drupal.org/node/2919303
|
||||
*
|
||||
* @Action(
|
||||
* id = "comment_save_action",
|
||||
* label = @Translation("Save comment"),
|
||||
* type = "comment"
|
||||
* )
|
||||
*/
|
||||
class SaveComment extends ActionBase {
|
||||
class SaveComment extends SaveAction {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function execute($comment = NULL) {
|
||||
$comment->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
|
||||
/** @var \Drupal\comment\CommentInterface $object */
|
||||
return $object->access('update', $account, $return_as_object);
|
||||
public function __construct($configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, TimeInterface $time) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition, $entity_type_manager, $time);
|
||||
@trigger_error(__NAMESPACE__ . '\SaveComment is deprecated in Drupal 8.5.x, will be removed before Drupal 9.0.0. Use \Drupal\Core\Action\Plugin\Action\SaveAction instead. See https://www.drupal.org/node/2919303.', 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;
|
||||
}
|
||||
|
|
|
@ -2,37 +2,32 @@
|
|||
|
||||
namespace Drupal\comment\Plugin\Action;
|
||||
|
||||
use Drupal\Core\Action\ActionBase;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\Core\Action\Plugin\Action\UnpublishAction;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
|
||||
/**
|
||||
* Unpublishes a comment.
|
||||
*
|
||||
* @deprecated in Drupal 8.5.x, to be removed before Drupal 9.0.0.
|
||||
* Use \Drupal\Core\Action\Plugin\Action\UnpublishAction instead.
|
||||
*
|
||||
* @see \Drupal\Core\Action\Plugin\Action\UnpublishAction
|
||||
* @see https://www.drupal.org/node/2919303
|
||||
*
|
||||
* @Action(
|
||||
* id = "comment_unpublish_action",
|
||||
* label = @Translation("Unpublish comment"),
|
||||
* type = "comment"
|
||||
* )
|
||||
*/
|
||||
class UnpublishComment extends ActionBase {
|
||||
class UnpublishComment extends UnpublishAction {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function execute($comment = NULL) {
|
||||
$comment->setPublished(FALSE);
|
||||
$comment->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
|
||||
/** @var \Drupal\comment\CommentInterface $object */
|
||||
$result = $object->status->access('edit', $account, TRUE)
|
||||
->andIf($object->access('update', $account, TRUE));
|
||||
|
||||
return $return_as_object ? $result : $result->isAllowed();
|
||||
public function __construct($configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition, $entity_type_manager);
|
||||
@trigger_error(__NAMESPACE__ . '\UnpublishComment is deprecated in Drupal 8.5.x, will be removed before Drupal 9.0.0. Use \Drupal\Core\Action\Plugin\Action\UnpublishAction instead. See https://www.drupal.org/node/2919303.', E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
@ -66,6 +66,8 @@ class CommentSelection extends DefaultSelection {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function entityQueryAlter(SelectInterface $query) {
|
||||
parent::entityQueryAlter($query);
|
||||
|
||||
$tables = $query->getTables();
|
||||
$data_table = 'comment_field_data';
|
||||
if (!isset($tables['comment_field_data']['alias'])) {
|
||||
|
@ -83,7 +85,7 @@ class CommentSelection extends DefaultSelection {
|
|||
|
||||
// Passing the query to node_query_node_access_alter() is sadly
|
||||
// insufficient for nodes.
|
||||
// @see SelectionEntityTypeNode::entityQueryAlter()
|
||||
// @see \Drupal\node\Plugin\EntityReferenceSelection\NodeSelection::buildEntityQuery()
|
||||
if (!$this->currentUser->hasPermission('bypass node access') && !count($this->moduleHandler->getImplementations('node_grants'))) {
|
||||
$query->condition($node_alias . '.status', 1);
|
||||
}
|
||||
|
|
|
@ -78,7 +78,7 @@ class CommentDefaultFormatter extends FormatterBase implements ContainerFactoryP
|
|||
protected $entityFormBuilder;
|
||||
|
||||
/**
|
||||
* @param \Drupal\Core\Routing\RouteMatchInterface $routeMatch
|
||||
* @var \Drupal\Core\Routing\RouteMatchInterface
|
||||
*/
|
||||
protected $routeMatch;
|
||||
|
||||
|
@ -192,12 +192,15 @@ class CommentDefaultFormatter extends FormatterBase implements ContainerFactoryP
|
|||
$elements['#cache']['contexts'][] = 'user.roles';
|
||||
if ($this->currentUser->hasPermission('post comments')) {
|
||||
$output['comment_form'] = [
|
||||
'#lazy_builder' => ['comment.lazy_builders:renderForm', [
|
||||
$entity->getEntityTypeId(),
|
||||
$entity->id(),
|
||||
$field_name,
|
||||
$this->getFieldSetting('comment_type'),
|
||||
]],
|
||||
'#lazy_builder' => [
|
||||
'comment.lazy_builders:renderForm',
|
||||
[
|
||||
$entity->getEntityTypeId(),
|
||||
$entity->id(),
|
||||
$field_name,
|
||||
$this->getFieldSetting('comment_type'),
|
||||
],
|
||||
],
|
||||
'#create_placeholder' => TRUE,
|
||||
];
|
||||
}
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\comment\Plugin\Field\FieldFormatter;
|
||||
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Field\FieldDefinitionInterface;
|
||||
use Drupal\Core\Field\Plugin\Field\FieldFormatter\StringFormatter;
|
||||
|
||||
/**
|
||||
* Plugin implementation of the 'comment_permalink' formatter.
|
||||
*
|
||||
* All the other entities use 'canonical' or 'revision' links to link the entity
|
||||
* to itself but comments use permalink URL.
|
||||
*
|
||||
* @FieldFormatter(
|
||||
* id = "comment_permalink",
|
||||
* label = @Translation("Comment Permalink"),
|
||||
* field_types = {
|
||||
* "string",
|
||||
* "uri",
|
||||
* },
|
||||
* quickedit = {
|
||||
* "editor" = "plain_text"
|
||||
* }
|
||||
* )
|
||||
*/
|
||||
class CommentPermalinkFormatter extends StringFormatter {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getEntityUrl(EntityInterface $comment) {
|
||||
/* @var $comment \Drupal\comment\CommentInterface */
|
||||
$comment_permalink = $comment->permalink();
|
||||
if ($comment->hasField('comment_body') && ($body = $comment->get('comment_body')->value)) {
|
||||
$attributes = $comment_permalink->getOption('attributes') ?: [];
|
||||
$attributes += ['title' => Unicode::truncate($body, 128)];
|
||||
$comment_permalink->setOption('attributes', $attributes);
|
||||
}
|
||||
return $comment_permalink;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function isApplicable(FieldDefinitionInterface $field_definition) {
|
||||
return parent::isApplicable($field_definition) && $field_definition->getTargetEntityTypeId() === 'comment' && $field_definition->getName() === 'subject';
|
||||
}
|
||||
|
||||
}
|
|
@ -21,7 +21,8 @@ use Drupal\Core\Session\AnonymousUserSession;
|
|||
* description = @Translation("This field manages configuration and presentation of comments on an entity."),
|
||||
* list_class = "\Drupal\comment\CommentFieldItemList",
|
||||
* default_widget = "comment_default",
|
||||
* default_formatter = "comment_default"
|
||||
* default_formatter = "comment_default",
|
||||
* cardinality = 1,
|
||||
* )
|
||||
*/
|
||||
class CommentItem extends FieldItemBase implements CommentItemInterface {
|
||||
|
@ -116,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',
|
||||
|
|
|
@ -7,6 +7,7 @@ use Drupal\Core\Menu\LocalTaskDefault;
|
|||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
|
||||
use Drupal\Core\StringTranslation\StringTranslationTrait;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
* Provides a local task that shows the amount of unapproved comments.
|
||||
|
@ -53,7 +54,7 @@ class UnapprovedComments extends LocalTaskDefault implements ContainerFactoryPlu
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getTitle() {
|
||||
public function getTitle(Request $request = NULL) {
|
||||
return $this->t('Unapproved comments (@count)', ['@count' => $this->commentStorage->getUnapprovedCount()]);
|
||||
}
|
||||
|
||||
|
|
47
web/core/modules/comment/src/Plugin/migrate/D7Comment.php
Normal file
47
web/core/modules/comment/src/Plugin/migrate/D7Comment.php
Normal file
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
|
@ -41,9 +41,9 @@ class EntityComment extends EntityContentBase {
|
|||
* The plugin_id for the plugin instance.
|
||||
* @param mixed $plugin_definition
|
||||
* The plugin implementation definition.
|
||||
* @param MigrationInterface $migration
|
||||
* @param \Drupal\migrate\Plugin\MigrationInterface $migration
|
||||
* The migration.
|
||||
* @param EntityStorageInterface $storage
|
||||
* @param \Drupal\Core\Entity\EntityStorageInterface $storage
|
||||
* The storage for this entity type.
|
||||
* @param array $bundles
|
||||
* The list of bundles this entity type has.
|
||||
|
|
|
@ -10,7 +10,7 @@ use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
|
|||
*
|
||||
* @MigrateSource(
|
||||
* id = "d6_comment",
|
||||
* source_provider = "comment"
|
||||
* source_module = "comment"
|
||||
* )
|
||||
*/
|
||||
class Comment extends DrupalSqlBase {
|
||||
|
@ -21,10 +21,11 @@ class Comment extends DrupalSqlBase {
|
|||
public function query() {
|
||||
$query = $this->select('comments', 'c')
|
||||
->fields('c', ['cid', 'pid', 'nid', 'uid', 'subject',
|
||||
'comment', 'hostname', 'timestamp', 'status', 'thread', 'name',
|
||||
'mail', 'homepage', 'format']);
|
||||
'comment', 'hostname', 'timestamp', 'status', 'thread', 'name',
|
||||
'mail', 'homepage', 'format',
|
||||
]);
|
||||
$query->innerJoin('node', 'n', 'c.nid = n.nid');
|
||||
$query->fields('n', ['type']);
|
||||
$query->fields('n', ['type', 'language']);
|
||||
$query->orderBy('c.timestamp');
|
||||
return $query;
|
||||
}
|
||||
|
@ -33,6 +34,20 @@ class Comment extends DrupalSqlBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function prepareRow(Row $row) {
|
||||
return parent::prepareRow($this->prepareComment($row));
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a backward compatibility layer for the deprecated migrate source
|
||||
* plugins d6_comment_variable and d6_comment_variable_per_comment_type.
|
||||
*
|
||||
* @param \Drupal\migrate\Row $row
|
||||
* The row from the source to process.
|
||||
* @return \Drupal\migrate\Row
|
||||
* The row object.
|
||||
* @deprecated in Drupal 8.4.x, to be removed before Drupal 9.0.x.
|
||||
*/
|
||||
protected function prepareComment(Row $row) {
|
||||
if ($this->variableGet('comment_subject_field_' . $row->getSourceProperty('type'), 1)) {
|
||||
// Comment subject visible.
|
||||
$row->setSourceProperty('field_name', 'comment');
|
||||
|
@ -42,10 +57,18 @@ class Comment extends DrupalSqlBase {
|
|||
$row->setSourceProperty('field_name', 'comment_no_subject');
|
||||
$row->setSourceProperty('comment_type', 'comment_no_subject');
|
||||
}
|
||||
|
||||
// In D6, status=0 means published, while in D8 means the opposite.
|
||||
// See https://www.drupal.org/node/237636.
|
||||
$row->setSourceProperty('status', !$row->getSourceProperty('status'));
|
||||
return parent::prepareRow($row);
|
||||
|
||||
// If node did not have a language, use site default language as a fallback.
|
||||
if (!$row->getSourceProperty('language')) {
|
||||
$language_default = $this->variableGet('language_default', NULL);
|
||||
$language = $language_default ? $language_default->language : 'en';
|
||||
$row->setSourceProperty('language', $language);
|
||||
}
|
||||
return $row;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -68,6 +91,7 @@ class Comment extends DrupalSqlBase {
|
|||
'mail' => $this->t("The comment author's email address from the comment form, if user is anonymous, and the 'Anonymous users may/must leave their contact information' setting is turned on."),
|
||||
'homepage' => $this->t("The comment author's home page address from the comment form, if user is anonymous, and the 'Anonymous users may/must leave their contact information' setting is turned on."),
|
||||
'type' => $this->t("The {node}.type to which this comment is a reply."),
|
||||
'language' => $this->t("The {node}.language to which this comment is a reply. Site default language is used as a fallback if node does not have a language."),
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -2,13 +2,19 @@
|
|||
|
||||
namespace Drupal\comment\Plugin\migrate\source\d6;
|
||||
|
||||
@trigger_error('CommentVariable is deprecated in Drupal 8.4.x and will be removed before Drupal 9.0.x. Use \Drupal\node\Plugin\migrate\source\d6\NodeType instead.', E_USER_DEPRECATED);
|
||||
|
||||
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
|
||||
use Drupal\migrate\Plugin\migrate\source\DummyQueryTrait;
|
||||
|
||||
/**
|
||||
* @MigrateSource(
|
||||
* id = "d6_comment_variable"
|
||||
* id = "d6_comment_variable",
|
||||
* source_module = "comment"
|
||||
* )
|
||||
*
|
||||
* @deprecated in Drupal 8.4.x, to be removed before Drupal 9.0.x. Use
|
||||
* \Drupal\node\Plugin\migrate\source\d6\NodeType instead.
|
||||
*/
|
||||
class CommentVariable extends DrupalSqlBase {
|
||||
|
||||
|
@ -24,7 +30,7 @@ class CommentVariable extends DrupalSqlBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function count() {
|
||||
public function count($refresh = FALSE) {
|
||||
return count($this->getCommentVariables());
|
||||
}
|
||||
|
||||
|
|
|
@ -2,10 +2,16 @@
|
|||
|
||||
namespace Drupal\comment\Plugin\migrate\source\d6;
|
||||
|
||||
@trigger_error('CommentVariablePerCommentType is deprecated in Drupal 8.4.x and will be removed before Drupal 9.0.x. Use \Drupal\node\Plugin\migrate\source\d6\NodeType instead.', E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* @MigrateSource(
|
||||
* id = "d6_comment_variable_per_comment_type"
|
||||
* id = "d6_comment_variable_per_comment_type",
|
||||
* source_module = "comment"
|
||||
* )
|
||||
*
|
||||
* @deprecated in Drupal 8.4.x, to be removed before Drupal 9.0.x. Use
|
||||
* \Drupal\node\Plugin\migrate\source\d6\NodeType instead.
|
||||
*/
|
||||
class CommentVariablePerCommentType extends CommentVariable {
|
||||
|
||||
|
@ -25,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 {
|
||||
|
@ -33,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'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ use Drupal\migrate_drupal\Plugin\migrate\source\d7\FieldableEntity;
|
|||
*
|
||||
* @MigrateSource(
|
||||
* id = "d7_comment",
|
||||
* source_provider = "comment"
|
||||
* source_module = "comment"
|
||||
* )
|
||||
*/
|
||||
class Comment extends FieldableEntity {
|
||||
|
@ -36,8 +36,29 @@ class Comment extends FieldableEntity {
|
|||
$comment_type = 'comment_node_' . $node_type;
|
||||
$row->setSourceProperty('comment_type', 'comment_node_' . $node_type);
|
||||
|
||||
foreach (array_keys($this->getFields('comment', $comment_type)) as $field) {
|
||||
$row->setSourceProperty($field, $this->getFieldValues('comment', $field, $cid));
|
||||
// If this entity was translated using Entity Translation, we need to get
|
||||
// its source language to get the field values in the right language.
|
||||
// The translations will be migrated by the d7_comment_entity_translation
|
||||
// migration.
|
||||
$entity_translatable = $this->isEntityTranslatable('comment') && (int) $this->variableGet('language_content_type_' . $node_type, 0) === 4;
|
||||
$source_language = $this->getEntityTranslationSourceLanguage('comment', $cid);
|
||||
$language = $entity_translatable && $source_language ? $source_language : $row->getSourceProperty('language');
|
||||
|
||||
// Get Field API field values.
|
||||
foreach ($this->getFields('comment', $comment_type) as $field_name => $field) {
|
||||
// Ensure we're using the right language if the entity and the field are
|
||||
// translatable.
|
||||
$field_language = $entity_translatable && $field['translatable'] ? $language : NULL;
|
||||
$row->setSourceProperty($field_name, $this->getFieldValues('comment', $field_name, $cid, NULL, $field_language));
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
@ -63,6 +84,7 @@ class Comment extends FieldableEntity {
|
|||
'name' => $this->t("The comment author's name. Uses {users}.name if the user is logged in, otherwise uses the value typed into the comment form."),
|
||||
'mail' => $this->t("The comment author's email address from the comment form, if user is anonymous, and the 'Anonymous users may/must leave their contact information' setting is turned on."),
|
||||
'homepage' => $this->t("The comment author's home page address from the comment form, if user is anonymous, and the 'Anonymous users may/must leave their contact information' setting is turned on."),
|
||||
'language' => $this->t('The comment language.'),
|
||||
'type' => $this->t("The {node}.type to which this comment is a reply."),
|
||||
];
|
||||
}
|
||||
|
|
|
@ -0,0 +1,103 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\comment\Plugin\migrate\source\d7;
|
||||
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\migrate_drupal\Plugin\migrate\source\d7\FieldableEntity;
|
||||
|
||||
/**
|
||||
* Provides Drupal 7 comment entity translation source plugin.
|
||||
*
|
||||
* @MigrateSource(
|
||||
* id = "d7_comment_entity_translation",
|
||||
* source_module = "entity_translation"
|
||||
* )
|
||||
*/
|
||||
class CommentEntityTranslation extends FieldableEntity {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
$query = $this->select('entity_translation', 'et')
|
||||
->fields('et')
|
||||
->fields('c', [
|
||||
'subject',
|
||||
])
|
||||
->condition('et.entity_type', 'comment')
|
||||
->condition('et.source', '', '<>');
|
||||
|
||||
$query->innerJoin('comment', 'c', 'c.cid = et.entity_id');
|
||||
$query->innerJoin('node', 'n', 'n.nid = c.nid');
|
||||
|
||||
$query->addField('n', 'type', 'node_type');
|
||||
|
||||
$query->orderBy('et.created');
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function prepareRow(Row $row) {
|
||||
$cid = $row->getSourceProperty('entity_id');
|
||||
$language = $row->getSourceProperty('language');
|
||||
$node_type = $row->getSourceProperty('node_type');
|
||||
$comment_type = 'comment_node_' . $node_type;
|
||||
|
||||
// Get Field API field values.
|
||||
foreach ($this->getFields('comment', $comment_type) as $field_name => $field) {
|
||||
// Ensure we're using the right language if the entity is translatable.
|
||||
$field_language = $field['translatable'] ? $language : NULL;
|
||||
$row->setSourceProperty($field_name, $this->getFieldValues('comment', $field_name, $cid, NULL, $field_language));
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
return [
|
||||
'entity_type' => $this->t('The entity type this translation relates to'),
|
||||
'entity_id' => $this->t('The entity ID this translation relates to'),
|
||||
'revision_id' => $this->t('The entity revision ID this translation relates to'),
|
||||
'language' => $this->t('The target language for this translation.'),
|
||||
'source' => $this->t('The source language from which this translation was created.'),
|
||||
'uid' => $this->t('The author of this translation.'),
|
||||
'status' => $this->t('Boolean indicating whether the translation is published (visible to non-administrators).'),
|
||||
'translate' => $this->t('A boolean indicating whether this translation needs to be updated.'),
|
||||
'created' => $this->t('The Unix timestamp when the translation was created.'),
|
||||
'changed' => $this->t('The Unix timestamp when the translation was most recently saved.'),
|
||||
'subject' => $this->t('The comment title.'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIds() {
|
||||
return [
|
||||
'entity_id' => [
|
||||
'type' => 'integer',
|
||||
'alias' => 'et',
|
||||
],
|
||||
'language' => [
|
||||
'type' => 'string',
|
||||
'alias' => 'et',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace Drupal\comment\Plugin\migrate\source\d7;
|
||||
|
||||
@trigger_error('CommentType is deprecated in Drupal 8.4.x and will be removed before Drupal 9.0.x. Use \Drupal\node\Plugin\migrate\source\d7\NodeType instead.', E_USER_DEPRECATED);
|
||||
|
||||
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
|
||||
|
@ -11,8 +13,11 @@ use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
|
|||
*
|
||||
* @MigrateSource(
|
||||
* id = "d7_comment_type",
|
||||
* source_provider = "comment"
|
||||
* source_module = "comment"
|
||||
* )
|
||||
*
|
||||
* @deprecated in Drupal 8.4.x, to be removed before Drupal 9.0.x. Use
|
||||
* \Drupal\node\Plugin\migrate\source\d7\NodeType instead.
|
||||
*/
|
||||
class CommentType extends DrupalSqlBase {
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Drupal\comment\Plugin\views\argument;
|
||||
|
||||
use Drupal\Core\Database\Connection;
|
||||
use Drupal\Core\Database\Query\Condition;
|
||||
use Drupal\views\Plugin\views\argument\ArgumentPluginBase;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
|
@ -24,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.
|
||||
|
@ -90,7 +91,7 @@ class UserUid extends ArgumentPluginBase {
|
|||
$subselect->where("c.entity_id = $this->tableAlias.$entity_id");
|
||||
$subselect->condition('c.entity_type', $entity_type);
|
||||
|
||||
$condition = db_or()
|
||||
$condition = (new Condition('OR'))
|
||||
->condition("$this->tableAlias.uid", $this->argument, '=')
|
||||
->exists($subselect);
|
||||
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\comment\Plugin\views\field;
|
||||
|
||||
use Drupal\views\Plugin\views\field\BulkForm;
|
||||
|
||||
/**
|
||||
* Defines a comment operations bulk form element.
|
||||
*
|
||||
* @ViewsField("comment_bulk_form")
|
||||
*/
|
||||
class CommentBulkForm extends BulkForm {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function emptySelectedMessage() {
|
||||
return $this->t('Select one or more comments to perform the update on.');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\comment\Plugin\views\field;
|
||||
|
||||
use Drupal\views\Plugin\views\field\EntityField;
|
||||
use Drupal\views\ResultRow;
|
||||
|
||||
/**
|
||||
* Views field display for commented entity.
|
||||
*
|
||||
* @ViewsField("commented_entity")
|
||||
*/
|
||||
class CommentedEntity extends EntityField {
|
||||
|
||||
/**
|
||||
* Array of entities that has comments.
|
||||
*
|
||||
* We use this to load all the commented entities of same entity type at once
|
||||
* to the EntityStorageController static cache.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $loadedCommentedEntities = [];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getItems(ResultRow $values) {
|
||||
if (empty($this->loadedCommentedEntities)) {
|
||||
$result = $this->view->result;
|
||||
|
||||
$entity_ids_per_type = [];
|
||||
foreach ($result as $value) {
|
||||
/** @var \Drupal\comment\CommentInterface $comment */
|
||||
if ($comment = $this->getEntity($value)) {
|
||||
$entity_ids_per_type[$comment->getCommentedEntityTypeId()][] = $comment->getCommentedEntityId();
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($entity_ids_per_type as $type => $ids) {
|
||||
$this->loadedCommentedEntities[$type] = $this->entityManager->getStorage($type)->loadMultiple($ids);
|
||||
}
|
||||
}
|
||||
|
||||
return parent::getItems($values);
|
||||
}
|
||||
|
||||
}
|
|
@ -72,7 +72,7 @@ class EntityLink extends FieldPluginBase {
|
|||
$entity = $this->getEntity($values);
|
||||
|
||||
// Only render the links, if they are defined.
|
||||
return !empty($this->build[$entity->id()]['links']['comment__comment']) ? drupal_render($this->build[$entity->id()]['links']['comment__comment']) : '';
|
||||
return !empty($this->build[$entity->id()]['links']['comment__comment']) ? \Drupal::service('renderer')->render($this->build[$entity->id()]['links']['comment__comment']) : '';
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
@ -70,7 +70,7 @@ class StatisticsLastCommentName extends FieldPluginBase {
|
|||
'#theme' => 'username',
|
||||
'#account' => $account,
|
||||
];
|
||||
return drupal_render($username);
|
||||
return \Drupal::service('renderer')->render($username);
|
||||
}
|
||||
else {
|
||||
return $this->sanitizeValue($this->getValue($values));
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\comment\Plugin\views\filter;
|
||||
|
||||
use Drupal\Core\Database\Query\Condition;
|
||||
use Drupal\views\Plugin\views\filter\FilterPluginBase;
|
||||
|
||||
/**
|
||||
|
@ -26,7 +27,7 @@ class UserUid extends FilterPluginBase {
|
|||
$subselect->where("c.entity_id = $this->tableAlias.$entity_id");
|
||||
$subselect->condition('c.entity_type', $entity_type);
|
||||
|
||||
$condition = db_or()
|
||||
$condition = (new Condition('OR'))
|
||||
->condition("$this->tableAlias.uid", $this->value, $this->operator)
|
||||
->exists($subselect);
|
||||
|
||||
|
|
|
@ -16,14 +16,14 @@ class Thread extends SortPluginBase {
|
|||
public function query() {
|
||||
$this->ensureMyTable();
|
||||
|
||||
//Read comment_render() in comment.module for an explanation of the
|
||||
//thinking behind this sort.
|
||||
// See \Drupal\comment\CommentStorage::loadThread() for an explanation of
|
||||
// the thinking behind this sort.
|
||||
if ($this->options['order'] == 'DESC') {
|
||||
$this->query->addOrderBy($this->tableAlias, $this->realField, $this->options['order']);
|
||||
}
|
||||
else {
|
||||
$alias = $this->tableAlias . '_' . $this->realField . 'asc';
|
||||
//@todo is this secure?
|
||||
// @todo is this secure?
|
||||
$this->query->addOrderBy(NULL, "SUBSTRING({$this->tableAlias}.{$this->realField}, 1, (LENGTH({$this->tableAlias}.{$this->realField}) - 1))", $this->options['order'], $alias);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,8 @@ class Comment extends WizardPluginBase {
|
|||
|
||||
/**
|
||||
* Set the created column.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $createdColumn = 'created';
|
||||
|
||||
|
@ -28,14 +30,6 @@ class Comment extends WizardPluginBase {
|
|||
* Set default values for the filters.
|
||||
*/
|
||||
protected $filters = [
|
||||
'status' => [
|
||||
'value' => TRUE,
|
||||
'table' => 'comment_field_data',
|
||||
'field' => 'status',
|
||||
'plugin_id' => 'boolean',
|
||||
'entity_type' => 'comment',
|
||||
'entity_field' => 'status',
|
||||
],
|
||||
'status_node' => [
|
||||
'value' => TRUE,
|
||||
'table' => 'node_field_data',
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace Drupal\comment\Tests;
|
||||
|
||||
@trigger_error(__NAMESPACE__ . '\CommentTestBase is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Use \Drupal\Tests\comment\Functional\CommentTestBase instead. See http://www.drupal.org/node/2908490', E_USER_DEPRECATED);
|
||||
|
||||
use Drupal\comment\Entity\CommentType;
|
||||
use Drupal\comment\Entity\Comment;
|
||||
use Drupal\comment\CommentInterface;
|
||||
|
@ -12,6 +14,11 @@ use Drupal\simpletest\WebTestBase;
|
|||
|
||||
/**
|
||||
* Provides setup and helper methods for comment tests.
|
||||
*
|
||||
* @deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0.
|
||||
* Use \Drupal\Tests\comment\Functional\CommentTestBase instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2908490
|
||||
*/
|
||||
abstract class CommentTestBase extends WebTestBase {
|
||||
|
||||
|
@ -159,7 +166,8 @@ abstract class CommentTestBase extends WebTestBase {
|
|||
preg_match('/#comment-([0-9]+)/', $this->getURL(), $match);
|
||||
|
||||
// Get comment.
|
||||
if ($contact !== TRUE) { // If true then attempting to find error message.
|
||||
if ($contact !== TRUE) {
|
||||
// If true then attempting to find error message.
|
||||
if ($subject) {
|
||||
$this->assertText($subject, 'Comment subject posted.');
|
||||
}
|
||||
|
@ -192,12 +200,12 @@ abstract class CommentTestBase extends WebTestBase {
|
|||
}
|
||||
|
||||
$comment_title = $comment_element[0]->xpath('div/h3/a');
|
||||
if (empty($comment_title) || ((string)$comment_title[0]) !== $comment->getSubject()) {
|
||||
if (empty($comment_title) || ((string) $comment_title[0]) !== $comment->getSubject()) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$comment_body = $comment_element[0]->xpath('div/div/p');
|
||||
if (empty($comment_body) || ((string)$comment_body[0]) !== $comment->comment_body->value) {
|
||||
if (empty($comment_body) || ((string) $comment_body[0]) !== $comment->comment_body->value) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
@ -354,7 +362,7 @@ abstract class CommentTestBase extends WebTestBase {
|
|||
$this->drupalPostForm('admin/content/comment' . ($approval ? '/approval' : ''), $edit, t('Update'));
|
||||
|
||||
if ($operation == 'delete') {
|
||||
$this->drupalPostForm(NULL, [], t('Delete comments'));
|
||||
$this->drupalPostForm(NULL, [], t('Delete'));
|
||||
$this->assertRaw(\Drupal::translation()->formatPlural(1, 'Deleted 1 comment.', 'Deleted @count comments.'), format_string('Operation "@operation" was performed on comment.', ['@operation' => $operation]));
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -2,13 +2,20 @@
|
|||
|
||||
namespace Drupal\comment\Tests\Views;
|
||||
|
||||
@trigger_error(__NAMESPACE__ . '\CommentTestBase is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Use \Drupal\Tests\comment\Functional\Views\CommentTestBase instead. See http://www.drupal.org/node/2908490', E_USER_DEPRECATED);
|
||||
|
||||
use Drupal\comment\Tests\CommentTestTrait;
|
||||
use Drupal\views\Tests\ViewTestBase;
|
||||
use Drupal\views\Tests\ViewTestData;
|
||||
use Drupal\comment\Entity\Comment;
|
||||
|
||||
/**
|
||||
* Tests the argument_comment_user_uid handler.
|
||||
* Provides setup and helper methods for comment views tests.
|
||||
*
|
||||
* @deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0.
|
||||
* Use \Drupal\Tests\comment\Functional\Views\CommentTestBase instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2908490
|
||||
*/
|
||||
abstract class CommentTestBase extends ViewTestBase {
|
||||
|
||||
|
@ -56,8 +63,8 @@ abstract class CommentTestBase extends ViewTestBase {
|
|||
*/
|
||||
protected $comment;
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
ViewTestData::createTestViews(get_class($this), ['comment_test_views']);
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -0,0 +1,120 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\comment\Functional;
|
||||
|
||||
use Drupal\comment\Entity\Comment;
|
||||
use Drupal\comment\Tests\CommentTestTrait;
|
||||
use Drupal\node\Entity\NodeType;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests comment administration and preview access.
|
||||
*
|
||||
* @group comment
|
||||
*/
|
||||
class CommentAccessTest extends BrowserTestBase {
|
||||
|
||||
use CommentTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = [
|
||||
'node',
|
||||
'comment',
|
||||
];
|
||||
|
||||
/**
|
||||
* Node for commenting.
|
||||
*
|
||||
* @var \Drupal\node\NodeInterface
|
||||
*/
|
||||
protected $unpublishedNode;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$node_type = NodeType::create([
|
||||
'type' => 'article',
|
||||
'name' => 'Article',
|
||||
]);
|
||||
$node_type->save();
|
||||
$node_author = $this->drupalCreateUser([
|
||||
'create article content',
|
||||
'access comments',
|
||||
]);
|
||||
|
||||
$this->drupalLogin($this->drupalCreateUser([
|
||||
'edit own comments',
|
||||
'skip comment approval',
|
||||
'post comments',
|
||||
'access comments',
|
||||
'access content',
|
||||
]));
|
||||
|
||||
$this->addDefaultCommentField('node', 'article');
|
||||
$this->unpublishedNode = $this->createNode([
|
||||
'title' => 'This is unpublished',
|
||||
'uid' => $node_author->id(),
|
||||
'status' => 0,
|
||||
'type' => 'article',
|
||||
]);
|
||||
$this->unpublishedNode->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests commenting disabled for access-blocked entities.
|
||||
*/
|
||||
public function testCannotCommentOnEntitiesYouCannotView() {
|
||||
$assert = $this->assertSession();
|
||||
|
||||
$comment_url = 'comment/reply/node/' . $this->unpublishedNode->id() . '/comment';
|
||||
|
||||
// Commenting on an unpublished node results in access denied.
|
||||
$this->drupalGet($comment_url);
|
||||
$assert->statusCodeEquals(403);
|
||||
|
||||
// Publishing the node grants access.
|
||||
$this->unpublishedNode->setPublished()->save();
|
||||
$this->drupalGet($comment_url);
|
||||
$assert->statusCodeEquals(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests cannot view comment reply form on entities you cannot view.
|
||||
*/
|
||||
public function testCannotViewCommentReplyFormOnEntitiesYouCannotView() {
|
||||
$assert = $this->assertSession();
|
||||
|
||||
// Create a comment on an unpublished node.
|
||||
$comment = Comment::create([
|
||||
'entity_type' => 'node',
|
||||
'name' => 'Tony',
|
||||
'hostname' => 'magic.example.com',
|
||||
'mail' => 'foo@example.com',
|
||||
'subject' => 'Comment on unpublished node',
|
||||
'entity_id' => $this->unpublishedNode->id(),
|
||||
'comment_type' => 'comment',
|
||||
'field_name' => 'comment',
|
||||
'pid' => 0,
|
||||
'uid' => $this->unpublishedNode->getOwnerId(),
|
||||
'status' => 1,
|
||||
]);
|
||||
$comment->save();
|
||||
|
||||
$comment_url = 'comment/reply/node/' . $this->unpublishedNode->id() . '/comment/' . $comment->id();
|
||||
|
||||
// Replying to a comment on an unpublished node results in access denied.
|
||||
$this->drupalGet($comment_url);
|
||||
$assert->statusCodeEquals(403);
|
||||
|
||||
// Publishing the node grants access.
|
||||
$this->unpublishedNode->setPublished()->save();
|
||||
$this->drupalGet($comment_url);
|
||||
$assert->statusCodeEquals(200);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\comment\Tests;
|
||||
namespace Drupal\Tests\comment\Functional;
|
||||
|
||||
use Drupal\comment\Entity\Comment;
|
||||
use Drupal\system\Entity\Action;
|
||||
|
@ -32,7 +32,7 @@ class CommentActionsTest extends CommentTestBase {
|
|||
$action = Action::load('comment_unpublish_action');
|
||||
$action->execute([$comment]);
|
||||
$this->assertTrue($comment->isPublished() === FALSE, 'Comment was unpublished');
|
||||
|
||||
$this->assertArraySubset(['module' => ['comment']], $action->getDependencies());
|
||||
// Publish a comment.
|
||||
$action = Action::load('comment_publish_action');
|
||||
$action->execute([$comment]);
|
|
@ -1,7 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\comment\Tests;
|
||||
namespace Drupal\Tests\comment\Functional;
|
||||
|
||||
use Drupal\Component\Render\FormattableMarkup;
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\user\RoleInterface;
|
||||
use Drupal\comment\Entity\Comment;
|
||||
|
||||
|
@ -29,7 +32,8 @@ class CommentAdminTest extends CommentTestBase {
|
|||
'skip comment approval' => FALSE,
|
||||
]);
|
||||
$this->drupalLogin($this->adminUser);
|
||||
$this->setCommentAnonymous('0'); // Ensure that doesn't require contact info.
|
||||
// Ensure that doesn't require contact info.
|
||||
$this->setCommentAnonymous('0');
|
||||
|
||||
// Test that the comments page loads correctly when there are no comments
|
||||
$this->drupalGet('admin/content/comment');
|
||||
|
@ -40,7 +44,8 @@ class CommentAdminTest extends CommentTestBase {
|
|||
// Post anonymous comment without contact info.
|
||||
$subject = $this->randomMachineName();
|
||||
$body = $this->randomMachineName();
|
||||
$this->postComment($this->node, $body, $subject, TRUE); // Set $contact to true so that it won't check for id and message.
|
||||
// Set $contact to true so that it won't check for id and message.
|
||||
$this->postComment($this->node, $body, $subject, TRUE);
|
||||
$this->assertText(t('Your comment has been queued for review by site administrators and will be published after approval.'), 'Comment requires approval.');
|
||||
|
||||
// Get unapproved comment id.
|
||||
|
@ -52,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();
|
||||
|
||||
|
@ -90,7 +95,7 @@ class CommentAdminTest extends CommentTestBase {
|
|||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Update'));
|
||||
$this->assertText(t('Are you sure you want to delete these comments and all their children?'), 'Confirmation required.');
|
||||
$this->drupalPostForm(NULL, $edit, t('Delete comments'));
|
||||
$this->drupalPostForm(NULL, [], t('Delete'));
|
||||
$this->assertText(t('No comments available.'), 'All comments were deleted.');
|
||||
// Test message when no comments selected.
|
||||
$edit = [
|
||||
|
@ -98,6 +103,15 @@ class CommentAdminTest extends CommentTestBase {
|
|||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Update'));
|
||||
$this->assertText(t('Select one or more comments to perform the update on.'));
|
||||
|
||||
// Make sure the label of unpublished node is not visible on listing page.
|
||||
$this->drupalGet('admin/content/comment');
|
||||
$this->postComment($this->node, $this->randomMachineName());
|
||||
$this->drupalGet('admin/content/comment');
|
||||
$this->assertText(Html::escape($this->node->label()));
|
||||
$this->node->setUnpublished()->save();
|
||||
$this->drupalGet('admin/content/comment');
|
||||
$this->assertNoText(Html::escape($this->node->label()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -111,13 +125,15 @@ class CommentAdminTest extends CommentTestBase {
|
|||
'skip comment approval' => FALSE,
|
||||
]);
|
||||
$this->drupalLogin($this->adminUser);
|
||||
$this->setCommentAnonymous('0'); // Ensure that doesn't require contact info.
|
||||
// Ensure that doesn't require contact info.
|
||||
$this->setCommentAnonymous('0');
|
||||
$this->drupalLogout();
|
||||
|
||||
// Post anonymous comment without contact info.
|
||||
$subject = $this->randomMachineName();
|
||||
$body = $this->randomMachineName();
|
||||
$this->postComment($this->node, $body, $subject, TRUE); // Set $contact to true so that it won't check for id and message.
|
||||
// Set $contact to true so that it won't check for id and message.
|
||||
$this->postComment($this->node, $body, $subject, TRUE);
|
||||
$this->assertText(t('Your comment has been queued for review by site administrators and will be published after approval.'), 'Comment requires approval.');
|
||||
|
||||
// Get unapproved comment id.
|
||||
|
@ -129,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();
|
||||
|
||||
|
@ -193,7 +209,8 @@ class CommentAdminTest extends CommentTestBase {
|
|||
|
||||
// Post anonymous comment.
|
||||
$this->drupalLogin($this->adminUser);
|
||||
$this->setCommentAnonymous('2'); // Ensure that we need email id before posting comment.
|
||||
// Ensure that we need email id before posting comment.
|
||||
$this->setCommentAnonymous('2');
|
||||
$this->drupalLogout();
|
||||
|
||||
// Post comment with contact info (required).
|
||||
|
@ -215,4 +232,51 @@ class CommentAdminTest extends CommentTestBase {
|
|||
$this->assertFieldById('edit-mail', $anonymous_comment->getAuthorEmail());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests commented translation deletion admin view.
|
||||
*/
|
||||
public function testCommentedTranslationDeletion() {
|
||||
\Drupal::service('module_installer')->install([
|
||||
'language',
|
||||
'locale',
|
||||
]);
|
||||
\Drupal::service('router.builder')->rebuildIfNeeded();
|
||||
|
||||
ConfigurableLanguage::createFromLangcode('ur')->save();
|
||||
// Rebuild the container to update the default language container variable.
|
||||
$this->rebuildContainer();
|
||||
// Ensure that doesn't require contact info.
|
||||
$this->setCommentAnonymous('0');
|
||||
$this->drupalLogin($this->webUser);
|
||||
$count_query = \Drupal::entityTypeManager()
|
||||
->getStorage('comment')
|
||||
->getQuery()
|
||||
->count();
|
||||
$before_count = $count_query->execute();
|
||||
// Post 2 anonymous comments without contact info.
|
||||
$comment1 = $this->postComment($this->node, $this->randomMachineName(), $this->randomMachineName(), TRUE);
|
||||
$comment2 = $this->postComment($this->node, $this->randomMachineName(), $this->randomMachineName(), TRUE);
|
||||
|
||||
$comment1->addTranslation('ur', ['subject' => 'ur ' . $comment1->label()])
|
||||
->save();
|
||||
$comment2->addTranslation('ur', ['subject' => 'ur ' . $comment1->label()])
|
||||
->save();
|
||||
$this->drupalLogout();
|
||||
$this->drupalLogin($this->adminUser);
|
||||
// Delete multiple comments in one operation.
|
||||
$edit = [
|
||||
'operation' => 'delete',
|
||||
"comments[{$comment1->id()}]" => 1,
|
||||
"comments[{$comment2->id()}]" => 1,
|
||||
];
|
||||
$this->drupalPostForm('admin/content/comment', $edit, t('Update'));
|
||||
$this->assertRaw(new FormattableMarkup('@label (Original translation) - <em>The following comment translations will be deleted:</em>', ['@label' => $comment1->label()]));
|
||||
$this->assertRaw(new FormattableMarkup('@label (Original translation) - <em>The following comment translations will be deleted:</em>', ['@label' => $comment2->label()]));
|
||||
$this->assertText('English');
|
||||
$this->assertText('Urdu');
|
||||
$this->drupalPostForm(NULL, [], t('Delete'));
|
||||
$after_count = $count_query->execute();
|
||||
$this->assertEqual($after_count, $before_count, 'No comment or translation found.');
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\comment\Tests;
|
||||
namespace Drupal\Tests\comment\Functional;
|
||||
|
||||
use Drupal\user\RoleInterface;
|
||||
|
||||
|
@ -43,7 +43,7 @@ class CommentAnonymousTest extends CommentTestBase {
|
|||
$edit['comment_body[0][value]'] = $body;
|
||||
$this->drupalPostForm($this->node->urlInfo(), $edit, t('Preview'));
|
||||
// Cannot use assertRaw here since both title and body are in the form.
|
||||
$preview = (string) $this->cssSelect('.preview')[0]->asXML();
|
||||
$preview = (string) $this->cssSelect('.preview')[0]->getHtml();
|
||||
$this->assertTrue(strpos($preview, $title) !== FALSE, 'Anonymous user can preview comment title.');
|
||||
$this->assertTrue(strpos($preview, $body) !== FALSE, 'Anonymous user can preview comment body.');
|
||||
|
||||
|
@ -56,7 +56,7 @@ class CommentAnonymousTest extends CommentTestBase {
|
|||
$edit['comment_body[0][value]'] = $body;
|
||||
$this->drupalPostForm($this->node->urlInfo(), $edit, t('Preview'));
|
||||
// Cannot use assertRaw here since both title and body are in the form.
|
||||
$preview = (string) $this->cssSelect('.preview')[0]->asXML();
|
||||
$preview = (string) $this->cssSelect('.preview')[0]->getHtml();
|
||||
$this->assertTrue(strpos($preview, $title) !== FALSE, 'Anonymous user can preview comment title.');
|
||||
$this->assertTrue(strpos($preview, $body) !== FALSE, 'Anonymous user can preview comment body.');
|
||||
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, ['skip comment approval']);
|
|
@ -1,8 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\comment\Tests;
|
||||
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.
|
|
@ -1,10 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\comment\Tests;
|
||||
namespace Drupal\Tests\comment\Functional;
|
||||
|
||||
use Drupal\comment\CommentInterface;
|
||||
use Drupal\comment\Tests\CommentTestTrait;
|
||||
use Drupal\node\Entity\Node;
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
use Drupal\comment\Entity\Comment;
|
||||
|
||||
/**
|
||||
|
@ -12,7 +13,7 @@ use Drupal\comment\Entity\Comment;
|
|||
*
|
||||
* @group comment
|
||||
*/
|
||||
class CommentBookTest extends WebTestBase {
|
||||
class CommentBookTest extends BrowserTestBase {
|
||||
|
||||
use CommentTestTrait;
|
||||
|
|
@ -1,11 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\comment\Tests;
|
||||
namespace Drupal\Tests\comment\Functional;
|
||||
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\comment\CommentInterface;
|
||||
use Drupal\user\RoleInterface;
|
||||
use Drupal\comment\Entity\Comment;
|
||||
use Drupal\Tests\Traits\Core\GeneratePermutationsTrait;
|
||||
|
||||
/**
|
||||
* Tests CSS classes on comments.
|
||||
|
@ -14,13 +15,15 @@ use Drupal\comment\Entity\Comment;
|
|||
*/
|
||||
class CommentCSSTest extends CommentTestBase {
|
||||
|
||||
use GeneratePermutationsTrait;
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Allow anonymous users to see comments.
|
||||
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, [
|
||||
'access comments',
|
||||
'access content'
|
||||
'access content',
|
||||
]);
|
||||
}
|
||||
|
|
@ -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.');
|
||||
}
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show more
Reference in a new issue