diff --git a/core/modules/comment/comment.admin.inc b/core/modules/comment/comment.admin.inc index 8f618e52f99a759b3036ffe7dac5866c6422c77b..99bb6b0a31f20ff9bd95f4600a67871fc77cd453 100644 --- a/core/modules/comment/comment.admin.inc +++ b/core/modules/comment/comment.admin.inc @@ -5,6 +5,8 @@ * Admin page callbacks for the Comment module. */ +use Drupal\comment\CommentInterface; + /** * Page callback: Presents an administrative comment listing. * @@ -70,7 +72,7 @@ function comment_admin_overview($form, &$form_state, $arg) { ); // Load the comments that need to be displayed. - $status = ($arg == 'approval') ? COMMENT_NOT_PUBLISHED : COMMENT_PUBLISHED; + $status = ($arg == 'approval') ? CommentInterface::NOT_PUBLISHED : CommentInterface::PUBLISHED; $header = array( 'subject' => array('data' => t('Subject'), 'field' => 'subject'), 'author' => array('data' => t('Author'), 'field' => 'name', 'class' => array(RESPONSIVE_PRIORITY_MEDIUM)), @@ -218,10 +220,10 @@ function comment_admin_overview_submit($form, &$form_state) { $comment = comment_load($value); if ($operation == 'unpublish') { - $comment->status->value = COMMENT_NOT_PUBLISHED; + $comment->status->value = CommentInterface::NOT_PUBLISHED; } elseif ($operation == 'publish') { - $comment->status->value = COMMENT_PUBLISHED; + $comment->status->value = CommentInterface::PUBLISHED; } $comment->save(); } diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 8debaef99c6f183a907485924b6f2de264dda976..145690b34f011b7aa01db28bf66592bc09681b3f 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -19,16 +19,6 @@ use Drupal\field\FieldInterface; use Drupal\file\FileInterface; -/** - * Comment is awaiting approval. - */ -const COMMENT_NOT_PUBLISHED = 0; - -/** - * Comment is published. - */ -const COMMENT_PUBLISHED = 1; - /** * Comments are displayed in a flat list - expanded. */ @@ -232,7 +222,7 @@ function comment_menu_alter(&$items) { */ function comment_count_unpublished() { $count = db_query('SELECT COUNT(cid) FROM {comment} WHERE status = :status', array( - ':status' => COMMENT_NOT_PUBLISHED, + ':status' => CommentInterface::NOT_PUBLISHED, ))->fetchField(); return t('Unapproved comments (@count)', array('@count' => $count)); } @@ -328,7 +318,7 @@ function comment_get_recent($number = 10) { $query = db_select('comment', 'c'); $query->addMetaData('base_table', 'comment'); $query->fields('c') - ->condition('c.status', COMMENT_PUBLISHED); + ->condition('c.status', CommentInterface::PUBLISHED); if (\Drupal::moduleHandler()->moduleExists('node')) { // Special case to filter by published content. $query->innerJoin('node_field_data', 'n', "n.nid = c.entity_id AND c.entity_type = 'node'"); @@ -391,7 +381,7 @@ function comment_new_page_count($num_comments, $new_replies, EntityInterface $en ->condition('entity_id', $entity->id()) ->condition('entity_type', $entity->entityType()) ->condition('field_id', $entity->entityType() . '__' . $field_name) - ->condition('status', COMMENT_PUBLISHED) + ->condition('status', CommentInterface::PUBLISHED) ->orderBy('created', 'DESC') ->orderBy('cid', 'DESC') ->range(0, $new_replies); @@ -412,7 +402,7 @@ function comment_new_page_count($num_comments, $new_replies, EntityInterface $en AND entity_type = :entity_type AND field_id = :field_id AND status = :status AND SUBSTRING(thread, 1, (LENGTH(thread) - 1)) < :thread', array( - ':status' => COMMENT_PUBLISHED, + ':status' => CommentInterface::PUBLISHED, ':entity_id' => $entity->id(), ':field_id' => $entity->entityType() . '__' . $field_name, ':entity_type' => $entity->entityType(), @@ -722,8 +712,8 @@ function comment_get_thread(EntityInterface $entity, $field_name, $mode, $commen ->addMetaData('field_name', $field_name); if (!user_access('administer comments')) { - $query->condition('c.status', COMMENT_PUBLISHED); - $count_query->condition('c.status', COMMENT_PUBLISHED); + $query->condition('c.status', CommentInterface::PUBLISHED); + $count_query->condition('c.status', CommentInterface::PUBLISHED); } if ($mode == COMMENT_MODE_FLAT) { $query->orderBy('c.cid', 'ASC'); @@ -1195,7 +1185,7 @@ function comment_num_new($entity_id, $entity_type, $field_name = NULL, $timestam $query->addExpression('COUNT(cid)'); $query->condition('c.entity_type', $entity_type) ->condition('c.entity_id', $entity_id) - ->condition('c.status', COMMENT_PUBLISHED) + ->condition('c.status', CommentInterface::PUBLISHED) ->condition('c.created', $timestamp, '>'); if ($field_name) { // Limit to a particular field. @@ -1236,7 +1226,7 @@ function comment_get_display_ordinal($cid, $instance) { $query->addExpression('COUNT(*)', 'count'); $query->condition('c2.cid', $cid); if (!user_access('administer comments')) { - $query->condition('c1.status', COMMENT_PUBLISHED); + $query->condition('c1.status', CommentInterface::PUBLISHED); } if ($instance->getSetting('default_mode') == COMMENT_MODE_FLAT) { @@ -1313,7 +1303,7 @@ function comment_preview(CommentInterface $comment, array &$form_state) { if ($comment->pid->target_id) { $build = array(); $parent = $comment->pid->entity; - if ($parent && $parent->status->value == COMMENT_PUBLISHED) { + if ($parent && $parent->status->value == CommentInterface::PUBLISHED) { $build = comment_view($parent); } } @@ -1478,7 +1468,7 @@ function template_preprocess_comment(&$variables) { $variables['status'] = 'preview'; } else { - $variables['status'] = ($comment->status->value == COMMENT_NOT_PUBLISHED) ? 'unpublished' : 'published'; + $variables['status'] = ($comment->status->value == CommentInterface::NOT_PUBLISHED) ? 'unpublished' : 'published'; } // Gather comment classes. @@ -1659,7 +1649,7 @@ function comment_ranking() { */ function comment_file_download_access($field, EntityInterface $entity, FileInterface $file) { if ($entity->entityType() == 'comment') { - if (user_access('access comments') && $entity->status->value == COMMENT_PUBLISHED || user_access('administer comments')) { + if (user_access('access comments') && $entity->status->value == CommentInterface::PUBLISHED || user_access('administer comments')) { $commented_entity = entity_load($entity->entity_type->value, $entity->entity_id->value); // Check access to parent entity. return $commented_entity->access('view'); diff --git a/core/modules/comment/lib/Drupal/comment/CommentAccessController.php b/core/modules/comment/lib/Drupal/comment/CommentAccessController.php index 800991f6fa0e517ce7b2d7922a30292b9b2f6f94..ce25a1caeba3b743c4a386e9e06d5855d112ac5a 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentAccessController.php +++ b/core/modules/comment/lib/Drupal/comment/CommentAccessController.php @@ -28,7 +28,7 @@ protected function checkAccess(EntityInterface $entity, $operation, $langcode, A break; case 'update': - return ($account->id() && $account->id() == $entity->uid->value && $entity->status->value == COMMENT_PUBLISHED && user_access('edit own comments', $account)) || user_access('administer comments', $account); + return ($account->id() && $account->id() == $entity->uid->value && $entity->status->value == CommentInterface::PUBLISHED && user_access('edit own comments', $account)) || user_access('administer comments', $account); break; case 'delete': diff --git a/core/modules/comment/lib/Drupal/comment/CommentFormController.php b/core/modules/comment/lib/Drupal/comment/CommentFormController.php index d0066a89810a456cc8d18e6b51506929ee5ffeac..8a5d52f9c8a49506f508aa5c5daa9e6b3619ca39 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentFormController.php +++ b/core/modules/comment/lib/Drupal/comment/CommentFormController.php @@ -117,7 +117,7 @@ public function form(array $form, array &$form_state) { // Prepare default values for form elements. if ($is_admin) { $author = $comment->name->value; - $status = (isset($comment->status->value) ? $comment->status->value : COMMENT_NOT_PUBLISHED); + $status = (isset($comment->status->value) ? $comment->status->value : CommentInterface::NOT_PUBLISHED); if (empty($form_state['comment_preview'])) { $form['#title'] = $this->t('Edit comment %title', array( '%title' => $comment->subject->value, @@ -131,7 +131,7 @@ public function form(array $form, array &$form_state) { else { $author = ($comment->name->value ? $comment->name->value : ''); } - $status = ($this->currentUser->hasPermission('skip comment approval') ? COMMENT_PUBLISHED : COMMENT_NOT_PUBLISHED); + $status = ($this->currentUser->hasPermission('skip comment approval') ? CommentInterface::PUBLISHED : CommentInterface::NOT_PUBLISHED); } $date = ''; @@ -195,8 +195,8 @@ public function form(array $form, array &$form_state) { '#title' => $this->t('Status'), '#default_value' => $status, '#options' => array( - COMMENT_PUBLISHED => $this->t('Published'), - COMMENT_NOT_PUBLISHED => $this->t('Not published'), + CommentInterface::PUBLISHED => $this->t('Published'), + CommentInterface::NOT_PUBLISHED => $this->t('Not published'), ), '#access' => $is_admin, ); @@ -383,7 +383,7 @@ public function save(array $form, array &$form_state) { watchdog('content', 'Comment posted: %subject.', array('%subject' => $comment->subject->value), WATCHDOG_NOTICE, l(t('view'), 'comment/' . $comment->id(), array('fragment' => 'comment-' . $comment->id()))); // Explain the approval queue if necessary. - if ($comment->status->value == COMMENT_NOT_PUBLISHED) { + if ($comment->status->value == CommentInterface::NOT_PUBLISHED) { 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.')); } diff --git a/core/modules/comment/lib/Drupal/comment/CommentInterface.php b/core/modules/comment/lib/Drupal/comment/CommentInterface.php index fe7f40d0c2dfa5d4a5392d376575b1989f97ed6d..28ec9fb4359ea1ec7f695769f8070a8f0b550a51 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentInterface.php +++ b/core/modules/comment/lib/Drupal/comment/CommentInterface.php @@ -15,6 +15,16 @@ */ interface CommentInterface extends ContentEntityInterface, EntityChangedInterface { + /** + * Comment is awaiting approval. + */ + const NOT_PUBLISHED = 0; + + /** + * Comment is published. + */ + const PUBLISHED = 1; + /** * Returns the permalink URL for this comment. * diff --git a/core/modules/comment/lib/Drupal/comment/CommentStorageController.php b/core/modules/comment/lib/Drupal/comment/CommentStorageController.php index 0d93c65608798e9c913034b230a5f24195f88de4..e23af78c7dfaf9edbe95088e63d965d783676d26 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentStorageController.php +++ b/core/modules/comment/lib/Drupal/comment/CommentStorageController.php @@ -62,7 +62,7 @@ public function updateEntityStatistics(CommentInterface $comment) { $count = $query->condition('c.entity_id', $comment->entity_id->value) ->condition('c.entity_type', $comment->entity_type->value) ->condition('c.field_id', $comment->field_id->value) - ->condition('c.status', COMMENT_PUBLISHED) + ->condition('c.status', CommentInterface::PUBLISHED) ->execute() ->fetchField(); @@ -73,7 +73,7 @@ public function updateEntityStatistics(CommentInterface $comment) { ->condition('c.entity_id', $comment->entity_id->value) ->condition('c.entity_type', $comment->entity_type->value) ->condition('c.field_id', $comment->field_id->value) - ->condition('c.status', COMMENT_PUBLISHED) + ->condition('c.status', CommentInterface::PUBLISHED) ->orderBy('c.created', 'DESC') ->range(0, 1) ->execute() diff --git a/core/modules/comment/lib/Drupal/comment/CommentStorageControllerInterface.php b/core/modules/comment/lib/Drupal/comment/CommentStorageControllerInterface.php index 69ba909d43a3fe8d7c5391773bd503b5b9ac46e4..4583f20883c0222b1e84ba0d794145acb7b533e9 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentStorageControllerInterface.php +++ b/core/modules/comment/lib/Drupal/comment/CommentStorageControllerInterface.php @@ -9,7 +9,6 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityStorageControllerInterface; -use Drupal\comment\CommentInterface; /** * Defines a common interface for comment entity controller classes. diff --git a/core/modules/comment/lib/Drupal/comment/CommentViewBuilder.php b/core/modules/comment/lib/Drupal/comment/CommentViewBuilder.php index be9c41f27dde8dd33dcc679b32ea1ba2ff92cfea..dc4cd61f4c4d9a056084f1e48587779c8811f0c7 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentViewBuilder.php +++ b/core/modules/comment/lib/Drupal/comment/CommentViewBuilder.php @@ -231,7 +231,7 @@ protected static function buildLinks(CommentInterface $entity, EntityInterface $ 'html' => TRUE, ); } - if ($entity->status->value == COMMENT_NOT_PUBLISHED && $entity->access('approve')) { + if ($entity->status->value == CommentInterface::NOT_PUBLISHED && $entity->access('approve')) { $links['comment-approve'] = array( 'title' => t('Approve'), 'route_name' => 'comment.approve', diff --git a/core/modules/comment/lib/Drupal/comment/Controller/CommentController.php b/core/modules/comment/lib/Drupal/comment/Controller/CommentController.php index ccb3a4aee3f5241c169c2e5f621043dceb34db7d..b1b127f8bb1a63ffd87a6053c2ab39a21fab3553 100644 --- a/core/modules/comment/lib/Drupal/comment/Controller/CommentController.php +++ b/core/modules/comment/lib/Drupal/comment/Controller/CommentController.php @@ -97,7 +97,7 @@ public static function create(ContainerInterface $container) { * @return \Symfony\Component\HttpFoundation\RedirectResponse. */ public function commentApprove(CommentInterface $comment) { - $comment->status->value = COMMENT_PUBLISHED; + $comment->status->value = CommentInterface::PUBLISHED; $comment->save(); drupal_set_message($this->t('Comment approved.')); @@ -246,7 +246,7 @@ public function getReplyForm(Request $request, $entity_type, $entity_id, $field_ // Load the parent comment. $comment = $this->entityManager()->getStorageController('comment')->load($pid); // Check if the parent comment is published and belongs to the current nid. - if (($comment->status->value == COMMENT_NOT_PUBLISHED) || ($comment->entity_id->value != $entity->id())) { + if (($comment->status->value == CommentInterface::NOT_PUBLISHED) || ($comment->entity_id->value != $entity->id())) { drupal_set_message($this->t('The comment you are replying to does not exist.'), 'error'); return new RedirectResponse($this->urlGenerator()->generateFromPath($uri['path'], array('absolute' => TRUE))); } diff --git a/core/modules/comment/lib/Drupal/comment/Entity/Comment.php b/core/modules/comment/lib/Drupal/comment/Entity/Comment.php index 1b29d84b1169af1565d4786b4e9592eec85ea7c7..d2c79bdc338af99a9a128a76c3569b2e2459e294 100644 --- a/core/modules/comment/lib/Drupal/comment/Entity/Comment.php +++ b/core/modules/comment/lib/Drupal/comment/Entity/Comment.php @@ -219,7 +219,7 @@ public function preSave(EntityStorageControllerInterface $storage_controller) { parent::preSave($storage_controller); if (!isset($this->status->value)) { - $this->status->value = \Drupal::currentUser()->hasPermission('skip comment approval') ? COMMENT_PUBLISHED : COMMENT_NOT_PUBLISHED; + $this->status->value = \Drupal::currentUser()->hasPermission('skip comment approval') ? CommentInterface::PUBLISHED : CommentInterface::NOT_PUBLISHED; } if ($this->isNew()) { // Add the comment to database. This next section builds the thread field. @@ -306,7 +306,7 @@ public function postSave(EntityStorageControllerInterface $storage_controller, $ $this->releaseThreadLock(); // Update the {comment_entity_statistics} table prior to executing the hook. $storage_controller->updateEntityStatistics($this); - if ($this->status->value == COMMENT_PUBLISHED) { + if ($this->status->value == CommentInterface::PUBLISHED) { module_invoke_all('comment_publish', $this); } } diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/Action/PublishComment.php b/core/modules/comment/lib/Drupal/comment/Plugin/Action/PublishComment.php index 93b9a99a3ea3fb1dad12f57c0e8d7d0919255692..9c11291d8c4a0d178e8e721dd6e4f48301568ad6 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/Action/PublishComment.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/Action/PublishComment.php @@ -10,6 +10,7 @@ use Drupal\Core\Annotation\Action; use Drupal\Core\Annotation\Translation; use Drupal\Core\Action\ActionBase; +use Drupal\comment\CommentInterface; /** * Publishes a comment. @@ -26,7 +27,7 @@ class PublishComment extends ActionBase { * {@inheritdoc} */ public function execute($comment = NULL) { - $comment->status->value = COMMENT_PUBLISHED; + $comment->status->value = CommentInterface::PUBLISHED; $comment->save(); } diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/Action/UnpublishByKeywordComment.php b/core/modules/comment/lib/Drupal/comment/Plugin/Action/UnpublishByKeywordComment.php index b7d735e0f0af0247e79f0cde06d2d5a5b836919a..f8350cc9d979d959d84d35372a88a14f6d7368ff 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/Action/UnpublishByKeywordComment.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/Action/UnpublishByKeywordComment.php @@ -10,6 +10,7 @@ use Drupal\Core\Annotation\Action; use Drupal\Core\Annotation\Translation; use Drupal\Core\Action\ConfigurableActionBase; +use Drupal\comment\CommentInterface; /** * Unpublishes a comment containing certain keywords. @@ -30,7 +31,7 @@ public function execute($comment = NULL) { $text = drupal_render($build); foreach ($this->configuration['keywords'] as $keyword) { if (strpos($text, $keyword) !== FALSE) { - $comment->status->value = COMMENT_NOT_PUBLISHED; + $comment->status->value = CommentInterface::NOT_PUBLISHED; $comment->save(); break; } diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/Action/UnpublishComment.php b/core/modules/comment/lib/Drupal/comment/Plugin/Action/UnpublishComment.php index 4857d3efe06fc69345ff033c037c92862891dadc..29a0b975b66bb0a9c58bf5cd79e76e8b0c2216bf 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/Action/UnpublishComment.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/Action/UnpublishComment.php @@ -10,6 +10,7 @@ use Drupal\Core\Annotation\Action; use Drupal\Core\Annotation\Translation; use Drupal\Core\Action\ActionBase; +use Drupal\comment\CommentInterface; /** * Unpublishes a comment. @@ -26,7 +27,7 @@ class UnpublishComment extends ActionBase { * {@inheritdoc} */ public function execute($comment = NULL) { - $comment->status->value = COMMENT_NOT_PUBLISHED; + $comment->status->value = CommentInterface::NOT_PUBLISHED; $comment->save(); } diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/entity_reference/selection/CommentSelection.php b/core/modules/comment/lib/Drupal/comment/Plugin/entity_reference/selection/CommentSelection.php index 13ce3d091a3e978c8f41b614b4c3141c7f728113..83ebc377ce260ce1c0bba019b21c5d5b34e975f4 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/entity_reference/selection/CommentSelection.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/entity_reference/selection/CommentSelection.php @@ -9,6 +9,7 @@ use Drupal\Core\Annotation\Translation; use Drupal\Core\Database\Query\SelectInterface; +use Drupal\comment\CommentInterface; use Drupal\entity_reference\Annotation\EntityReferenceSelection; use Drupal\entity_reference\Plugin\entity_reference\selection\SelectionBase; @@ -35,7 +36,7 @@ public function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS') { // core requires us to also know about the concept of 'published' and // 'unpublished'. if (!user_access('administer comments')) { - $query->condition('status', COMMENT_PUBLISHED); + $query->condition('status', CommentInterface::PUBLISHED); } return $query; } diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/views/field/LinkApprove.php b/core/modules/comment/lib/Drupal/comment/Plugin/views/field/LinkApprove.php index 5fd785a2dac49b38360ea74c1e7abaa663ef1689..6344b9e13942005244dfd32423c2100f45334b2b 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/views/field/LinkApprove.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/views/field/LinkApprove.php @@ -7,6 +7,7 @@ namespace Drupal\comment\Plugin\views\field; +use Drupal\comment\CommentInterface; use Drupal\views\ResultRow; use Drupal\Component\Annotation\PluginID; @@ -39,7 +40,7 @@ protected function renderLink($data, ResultRow $values) { $status = $this->getValue($values, 'status'); // Don't show an approve link on published nodes. - if ($status == COMMENT_PUBLISHED) { + if ($status == CommentInterface::PUBLISHED) { return; } diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/views/field/NodeNewComments.php b/core/modules/comment/lib/Drupal/comment/Plugin/views/field/NodeNewComments.php index 3ce1d29ed009fc63c6d7051dcfda05ec15d4ba30..270136e0070ffd0fa159dc09a4ec32b7cff470c8 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/views/field/NodeNewComments.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/views/field/NodeNewComments.php @@ -9,6 +9,7 @@ use Drupal\Component\Annotation\PluginID; use Drupal\Core\Database\Connection; +use Drupal\comment\CommentInterface; use Drupal\views\Plugin\views\field\Numeric; use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\views\ResultRow; @@ -121,7 +122,7 @@ public function preRender(&$values) { $result = $this->database->query("SELECT n.nid, COUNT(c.cid) as num_comments FROM {node} n INNER JOIN {comment} c ON n.nid = c.entity_id AND c.entity_type = 'node' LEFT JOIN {history} h ON h.nid = n.nid AND h.uid = :h_uid WHERE n.nid IN (:nids) AND c.changed > GREATEST(COALESCE(h.timestamp, :timestamp), :timestamp) AND c.status = :status GROUP BY n.nid", array( - ':status' => COMMENT_PUBLISHED, + ':status' => CommentInterface::PUBLISHED, ':h_uid' => $user->id(), ':nids' => $nids, ':timestamp' => HISTORY_READ_LIMIT, diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentActionsTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentActionsTest.php index 94a1651b0c0da58b4f634d70fd16420f40f98b21..ea892c87be1e54898a09c74c54cdf017c579fecc 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentActionsTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentActionsTest.php @@ -7,6 +7,8 @@ namespace Drupal\comment\Tests; +use Drupal\comment\CommentInterface; + /** * Tests actions provided by the Comment module. */ @@ -39,12 +41,12 @@ function testCommentPublishUnpublishActions() { // Unpublish a comment. $action = entity_load('action', 'comment_unpublish_action'); $action->execute(array($comment)); - $this->assertEqual($comment->status->value, COMMENT_NOT_PUBLISHED, 'Comment was unpublished'); + $this->assertEqual($comment->status->value, CommentInterface::NOT_PUBLISHED, 'Comment was unpublished'); // Publish a comment. $action = entity_load('action', 'comment_publish_action'); $action->execute(array($comment)); - $this->assertEqual($comment->status->value, COMMENT_PUBLISHED, 'Comment was published'); + $this->assertEqual($comment->status->value, CommentInterface::PUBLISHED, 'Comment was published'); } /** @@ -70,10 +72,10 @@ function testCommentUnpublishByKeyword() { // Load the full comment so that status is available. $comment = comment_load($comment->id()); - $this->assertTrue($comment->status->value == COMMENT_PUBLISHED, 'The comment status was set to published.'); + $this->assertTrue($comment->status->value == CommentInterface::PUBLISHED, 'The comment status was set to published.'); $action->execute(array($comment)); - $this->assertTrue($comment->status->value == COMMENT_NOT_PUBLISHED, 'The comment status was set to not published.'); + $this->assertTrue($comment->status->value == CommentInterface::NOT_PUBLISHED, 'The comment status was set to not published.'); } } diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentCSSTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentCSSTest.php index 1e9828706ea960bde5ef60490630d3731caa3f74..91b9d45eda70437e2ff8f9df5eec7e079f3ea6e2 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentCSSTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentCSSTest.php @@ -8,6 +8,7 @@ namespace Drupal\comment\Tests; use Drupal\Core\Language\Language; +use Drupal\comment\CommentInterface; /** * Tests comment CSS classes. @@ -40,7 +41,7 @@ function testCommentClasses() { $parameters = array( 'node_uid' => array(0, $this->web_user->id()), 'comment_uid' => array(0, $this->web_user->id(), $this->admin_user->id()), - 'comment_status' => array(COMMENT_PUBLISHED, COMMENT_NOT_PUBLISHED), + 'comment_status' => array(CommentInterface::PUBLISHED, CommentInterface::NOT_PUBLISHED), 'user' => array('anonymous', 'authenticated', 'admin'), ); $permutations = $this->generatePermutations($parameters); @@ -90,7 +91,7 @@ function testCommentClasses() { $this->assertIdentical(1, count($this->xpath('//*[@data-history-node-id="' . $node->id() . '"]')), 'data-history-node-id attribute is set on node.'); // Verify classes if the comment is visible for the current user. - if ($case['comment_status'] == COMMENT_PUBLISHED || $case['user'] == 'admin') { + if ($case['comment_status'] == CommentInterface::PUBLISHED || $case['user'] == 'admin') { // Verify the by-anonymous class. $comments = $this->xpath('//*[contains(@class, "comment") and contains(@class, "by-anonymous")]'); if ($case['comment_uid'] == 0) { @@ -119,7 +120,7 @@ function testCommentClasses() { // Verify the unpublished class. $comments = $this->xpath('//*[contains(@class, "comment") and contains(@class, "unpublished")]'); - if ($case['comment_status'] == COMMENT_NOT_PUBLISHED && $case['user'] == 'admin') { + if ($case['comment_status'] == CommentInterface::NOT_PUBLISHED && $case['user'] == 'admin') { $this->assertTrue(count($comments) == 1, 'unpublished class found.'); } else { @@ -130,7 +131,7 @@ function testCommentClasses() { // drupal.comment-new-indicator library to add a "new" indicator to each // comment that was created or changed after the last time the current // user read the corresponding node. - if ($case['comment_status'] == COMMENT_PUBLISHED || $case['user'] == 'admin') { + if ($case['comment_status'] == CommentInterface::PUBLISHED || $case['user'] == 'admin') { $this->assertIdentical(1, count($this->xpath('//*[contains(@class, "comment")]/*[@data-comment-timestamp="' . $comment->changed->value . '"]')), 'data-comment-timestamp attribute is set on comment'); $expectedJS = ($case['user'] !== 'anonymous'); $this->assertIdentical($expectedJS, isset($settings['ajaxPageState']['js']['core/modules/comment/js/comment-new-indicator.js']), 'drupal.comment-new-indicator library is present.'); diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentInterfaceTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentInterfaceTest.php index b0311cba66f59990e8c6521dd7a63e781ba31c47..1e13ddb8901a2c72859a4f10f9600b754d02b1e2 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentInterfaceTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentInterfaceTest.php @@ -7,6 +7,8 @@ namespace Drupal\comment\Tests; +use Drupal\comment\CommentInterface; + /** * Tests the comment module administrative and end-user-facing interfaces. */ @@ -146,7 +148,7 @@ function testCommentInterface() { $this->setCommentsPerPage(50); // Attempt to reply to an unpublished comment. - $reply_loaded->status->value = COMMENT_NOT_PUBLISHED; + $reply_loaded->status->value = CommentInterface::NOT_PUBLISHED; $reply_loaded->save(); $this->drupalGet('comment/reply/node/' . $this->node->id() . '/comment/' . $reply_loaded->id()); $this->assertText(t('The comment you are replying to does not exist.'), 'Replying to an unpublished comment'); diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentLinksTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentLinksTest.php index c529ab9c10734326fc827196a4aec6519e48087a..6eabd64f5292eb3a462ecf7a16ce9ae81647cf9c 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentLinksTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentLinksTest.php @@ -8,6 +8,7 @@ namespace Drupal\comment\Tests; use Drupal\Core\Language\Language; +use Drupal\comment\CommentInterface; /** * Tests comment links based on environment configurations. @@ -146,7 +147,7 @@ function setEnvironment(array $info) { 'field_name' => 'comment', 'pid' => 0, 'uid' => 0, - 'status' => COMMENT_PUBLISHED, + 'status' => CommentInterface::PUBLISHED, 'subject' => $this->randomName(), 'hostname' => '127.0.0.1', 'langcode' => Language::LANGCODE_NOT_SPECIFIED, diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentNewIndicatorTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentNewIndicatorTest.php index cdf658ac2c0e9768762f7f422731a81f4cbd7cd5..17e358c4b43bd3c4d93fe0c52c0441a3d440b92f 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentNewIndicatorTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentNewIndicatorTest.php @@ -8,6 +8,7 @@ namespace Drupal\comment\Tests; use Drupal\Core\Language\Language; +use Drupal\comment\CommentInterface; /** * Tests the 'new' marker on comments. @@ -94,7 +95,7 @@ public function testCommentNewCommentsIndicator() { 'field_name' => 'comment', 'pid' => 0, 'uid' => $this->loggedInUser->id(), - 'status' => COMMENT_PUBLISHED, + 'status' => CommentInterface::PUBLISHED, 'subject' => $this->randomName(), 'hostname' => '127.0.0.1', 'langcode' => Language::LANGCODE_NOT_SPECIFIED, diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionAccessTest.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionAccessTest.php index 98373ae2b9aef7e442222d512672416feff66bec..3fb64605d63497573817d80308252f3000b67cbe 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionAccessTest.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionAccessTest.php @@ -9,6 +9,7 @@ use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Language\Language; +use Drupal\comment\CommentInterface; use Drupal\simpletest\WebTestBase; /** @@ -407,7 +408,7 @@ public function testCommentHandler() { 'uid' => 1, 'cid' => NULL, 'pid' => 0, - 'status' => COMMENT_PUBLISHED, + 'status' => CommentInterface::PUBLISHED, 'subject' => 'Comment Published <&>', 'language' => Language::LANGCODE_NOT_SPECIFIED, ), @@ -418,7 +419,7 @@ public function testCommentHandler() { 'uid' => 1, 'cid' => NULL, 'pid' => 0, - 'status' => COMMENT_NOT_PUBLISHED, + 'status' => CommentInterface::NOT_PUBLISHED, 'subject' => 'Comment Unpublished <&>', 'language' => Language::LANGCODE_NOT_SPECIFIED, ), @@ -429,7 +430,7 @@ public function testCommentHandler() { 'uid' => 1, 'cid' => NULL, 'pid' => 0, - 'status' => COMMENT_NOT_PUBLISHED, + 'status' => CommentInterface::NOT_PUBLISHED, 'subject' => 'Comment Published on Unpublished node <&>', 'language' => Language::LANGCODE_NOT_SPECIFIED, ), diff --git a/core/modules/forum/lib/Drupal/forum/ForumManager.php b/core/modules/forum/lib/Drupal/forum/ForumManager.php index cdf9a5e48ea62b716565b145f2d2ac32bce5049e..5c530c7e6856ed72ac5bc97d10df76597b600474 100644 --- a/core/modules/forum/lib/Drupal/forum/ForumManager.php +++ b/core/modules/forum/lib/Drupal/forum/ForumManager.php @@ -11,6 +11,7 @@ use Drupal\Core\Database\Connection; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\StringTranslation\TranslationInterface; +use Drupal\comment\CommentInterface; use Drupal\field\FieldInfo; use Drupal\node\NodeInterface; @@ -518,14 +519,14 @@ public function unreadTopics($term, $uid) { public function updateIndex($nid) { $count = $this->connection->query("SELECT COUNT(cid) FROM {comment} c INNER JOIN {forum_index} i ON c.entity_id = i.nid WHERE c.entity_id = :nid AND c.field_id = 'node__comment_forum' AND c.entity_type = 'node' AND c.status = :status", array( ':nid' => $nid, - ':status' => COMMENT_PUBLISHED, + ':status' => CommentInterface::PUBLISHED, ))->fetchField(); if ($count > 0) { // Comments exist. $last_reply = $this->connection->queryRange("SELECT cid, name, created, uid FROM {comment} WHERE entity_id = :nid AND field_id = 'node__comment_forum' AND entity_type = 'node' AND status = :status ORDER BY cid DESC", 0, 1, array( ':nid' => $nid, - ':status' => COMMENT_PUBLISHED, + ':status' => CommentInterface::PUBLISHED, ))->fetchObject(); $this->connection->update('forum_index') ->fields( array( diff --git a/core/modules/forum/lib/Drupal/forum/Tests/ForumUninstallTest.php b/core/modules/forum/lib/Drupal/forum/Tests/ForumUninstallTest.php index d1f0e65c1fb84c1f0aada85e8a84a237cf65ddd8..fed13531063f13fa0b3c25c6fc7927a11536dbd7 100644 --- a/core/modules/forum/lib/Drupal/forum/Tests/ForumUninstallTest.php +++ b/core/modules/forum/lib/Drupal/forum/Tests/ForumUninstallTest.php @@ -7,6 +7,7 @@ namespace Drupal\forum\Tests; +use Drupal\comment\CommentInterface; use Drupal\simpletest\WebTestBase; /** @@ -62,7 +63,7 @@ function testForumUninstallWithField() { 'field_name' => 'comment_forum', 'pid' => 0, 'uid' => 0, - 'status' => COMMENT_PUBLISHED, + 'status' => CommentInterface::PUBLISHED, 'subject' => $this->randomName(), 'hostname' => '127.0.0.1', )); diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeAccessPagerTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeAccessPagerTest.php index 579626a9a1f5e85ba08e4333d585674c504f41d7..74cd9c742aa60ffd70fa616aaffc39945ccc2b7b 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeAccessPagerTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeAccessPagerTest.php @@ -8,6 +8,7 @@ namespace Drupal\node\Tests; use Drupal\Core\Language\Language; +use Drupal\comment\CommentInterface; use Drupal\simpletest\WebTestBase; /** @@ -55,7 +56,7 @@ public function testCommentPager() { 'comment_body' => array( array('value' => $this->randomName()), ), - 'status' => COMMENT_PUBLISHED, + 'status' => CommentInterface::PUBLISHED, )); $comment->save(); } diff --git a/core/modules/system/lib/Drupal/system/Tests/Theme/EntityFilteringThemeTest.php b/core/modules/system/lib/Drupal/system/Tests/Theme/EntityFilteringThemeTest.php index 411f6fee6ca5feacb95f49df7ca3491fdc804dad..8a96631d2f0dc79d981f6204e11a2666ca93cd21 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Theme/EntityFilteringThemeTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Theme/EntityFilteringThemeTest.php @@ -7,6 +7,7 @@ namespace Drupal\system\Tests\Theme; +use Drupal\comment\CommentInterface; use Drupal\simpletest\WebTestBase; /** @@ -112,7 +113,7 @@ function setUp() { 'entity_id' => $this->node->id(), 'entity_type' => 'node', 'field_name' => 'comment', - 'status' => COMMENT_PUBLISHED, + 'status' => CommentInterface::PUBLISHED, 'subject' => $this->xss_label, 'comment_body' => array($this->randomName()), )); diff --git a/core/modules/tracker/lib/Drupal/tracker/Tests/TrackerTest.php b/core/modules/tracker/lib/Drupal/tracker/Tests/TrackerTest.php index 7a3983e36a7f113235ce010f347e7085dc3a4461..0abd95e13a05a7a962de4bb2c15b2c343ade2e80 100644 --- a/core/modules/tracker/lib/Drupal/tracker/Tests/TrackerTest.php +++ b/core/modules/tracker/lib/Drupal/tracker/Tests/TrackerTest.php @@ -7,6 +7,7 @@ namespace Drupal\tracker\Tests; +use Drupal\comment\CommentInterface; use Drupal\simpletest\WebTestBase; /** @@ -121,7 +122,7 @@ function testTrackerUser() { // Verify that unpublished comments are removed from the tracker. $admin_user = $this->drupalCreateUser(array('post comments', 'administer comments', 'access user profiles')); $this->drupalLogin($admin_user); - $this->drupalPostForm('comment/1/edit', array('status' => COMMENT_NOT_PUBLISHED), t('Save')); + $this->drupalPostForm('comment/1/edit', array('status' => CommentInterface::NOT_PUBLISHED), t('Save')); $this->drupalGet('user/' . $this->user->id() . '/track'); $this->assertNoText($other_published_my_comment->label(), 'Unpublished comments are not counted on the tracker listing.'); } diff --git a/core/modules/tracker/tracker.module b/core/modules/tracker/tracker.module index eca8ccc944decf61579aa7221188519734486707..b1be0414a3e07dbb43787277d669dcd617bd9dae 100644 --- a/core/modules/tracker/tracker.module +++ b/core/modules/tracker/tracker.module @@ -6,6 +6,7 @@ */ use Drupal\Core\Entity\EntityInterface; +use Drupal\comment\CommentInterface; use Drupal\node\NodeInterface; use Drupal\Core\Session\AccountInterface; @@ -92,7 +93,7 @@ function tracker_cron() { ->condition('c.entity_id', $row->nid) ->condition('c.entity_type', 'node') ->condition('c.uid', $row->uid, '<>') - ->condition('c.status', COMMENT_PUBLISHED); + ->condition('c.status', CommentInterface::PUBLISHED); // Insert the user-level data for the commenters (except if a commenter // is the node's author). @@ -193,7 +194,7 @@ function tracker_node_predelete(EntityInterface $node, $arg = 0) { function tracker_comment_update($comment) { // $comment->save() calls hook_comment_publish() for all published comments // so we need to handle all other values here. - if ($comment->status->value != COMMENT_PUBLISHED && $comment->entity_type->value == 'node') { + if ($comment->status->value != CommentInterface::PUBLISHED && $comment->entity_type->value == 'node') { _tracker_remove($comment->entity_id->target_id, $comment->uid->target_id, $comment->changed->value); } } @@ -285,7 +286,7 @@ function _tracker_calculate_changed($nid) { $changed = db_query('SELECT changed FROM {node_field_data} WHERE nid = :nid AND default_langcode = 1 ORDER BY changed DESC', array(':nid' => $nid), array('target' => 'slave'))->fetchField(); $latest_comment = db_query_range("SELECT cid, changed FROM {comment} WHERE entity_type = 'node' AND entity_id = :nid AND status = :status ORDER BY changed DESC", 0, 1, array( ':nid' => $nid, - ':status' => COMMENT_PUBLISHED, + ':status' => CommentInterface::PUBLISHED, ), array('target' => 'slave'))->fetchObject(); if ($latest_comment && $latest_comment->changed > $changed) { $changed = $latest_comment->changed; @@ -319,7 +320,7 @@ function _tracker_remove($nid, $uid = NULL, $changed = NULL) { $keep_subscription = db_query_range("SELECT COUNT(*) FROM {comment} WHERE entity_type = 'node' AND entity_id = :nid AND uid = :uid AND status = :status", 0, 1, array( ':nid' => $nid, ':uid' => $uid, - ':status' => COMMENT_PUBLISHED, + ':status' => CommentInterface::PUBLISHED, ))->fetchField(); }