diff --git a/core/modules/comment/comment.admin.inc b/core/modules/comment/comment.admin.inc index 99bb6b0..8f618e5 100644 --- a/core/modules/comment/comment.admin.inc +++ b/core/modules/comment/comment.admin.inc @@ -5,8 +5,6 @@ * Admin page callbacks for the Comment module. */ -use Drupal\comment\CommentInterface; - /** * Page callback: Presents an administrative comment listing. * @@ -72,7 +70,7 @@ function comment_admin_overview($form, &$form_state, $arg) { ); // Load the comments that need to be displayed. - $status = ($arg == 'approval') ? CommentInterface::NOT_PUBLISHED : CommentInterface::PUBLISHED; + $status = ($arg == 'approval') ? COMMENT_NOT_PUBLISHED : COMMENT_PUBLISHED; $header = array( 'subject' => array('data' => t('Subject'), 'field' => 'subject'), 'author' => array('data' => t('Author'), 'field' => 'name', 'class' => array(RESPONSIVE_PRIORITY_MEDIUM)), @@ -220,10 +218,10 @@ function comment_admin_overview_submit($form, &$form_state) { $comment = comment_load($value); if ($operation == 'unpublish') { - $comment->status->value = CommentInterface::NOT_PUBLISHED; + $comment->status->value = COMMENT_NOT_PUBLISHED; } elseif ($operation == 'publish') { - $comment->status->value = CommentInterface::PUBLISHED; + $comment->status->value = COMMENT_PUBLISHED; } $comment->save(); } diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 145690b..8debaef 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -20,6 +20,16 @@ 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. */ const COMMENT_MODE_FLAT = 0; @@ -222,7 +232,7 @@ function comment_menu_alter(&$items) { */ function comment_count_unpublished() { $count = db_query('SELECT COUNT(cid) FROM {comment} WHERE status = :status', array( - ':status' => CommentInterface::NOT_PUBLISHED, + ':status' => COMMENT_NOT_PUBLISHED, ))->fetchField(); return t('Unapproved comments (@count)', array('@count' => $count)); } @@ -318,7 +328,7 @@ function comment_get_recent($number = 10) { $query = db_select('comment', 'c'); $query->addMetaData('base_table', 'comment'); $query->fields('c') - ->condition('c.status', CommentInterface::PUBLISHED); + ->condition('c.status', COMMENT_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'"); @@ -381,7 +391,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', CommentInterface::PUBLISHED) + ->condition('status', COMMENT_PUBLISHED) ->orderBy('created', 'DESC') ->orderBy('cid', 'DESC') ->range(0, $new_replies); @@ -402,7 +412,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' => CommentInterface::PUBLISHED, + ':status' => COMMENT_PUBLISHED, ':entity_id' => $entity->id(), ':field_id' => $entity->entityType() . '__' . $field_name, ':entity_type' => $entity->entityType(), @@ -712,8 +722,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', CommentInterface::PUBLISHED); - $count_query->condition('c.status', CommentInterface::PUBLISHED); + $query->condition('c.status', COMMENT_PUBLISHED); + $count_query->condition('c.status', COMMENT_PUBLISHED); } if ($mode == COMMENT_MODE_FLAT) { $query->orderBy('c.cid', 'ASC'); @@ -1185,7 +1195,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', CommentInterface::PUBLISHED) + ->condition('c.status', COMMENT_PUBLISHED) ->condition('c.created', $timestamp, '>'); if ($field_name) { // Limit to a particular field. @@ -1226,7 +1236,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', CommentInterface::PUBLISHED); + $query->condition('c1.status', COMMENT_PUBLISHED); } if ($instance->getSetting('default_mode') == COMMENT_MODE_FLAT) { @@ -1303,7 +1313,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 == CommentInterface::PUBLISHED) { + if ($parent && $parent->status->value == COMMENT_PUBLISHED) { $build = comment_view($parent); } } @@ -1468,7 +1478,7 @@ function template_preprocess_comment(&$variables) { $variables['status'] = 'preview'; } else { - $variables['status'] = ($comment->status->value == CommentInterface::NOT_PUBLISHED) ? 'unpublished' : 'published'; + $variables['status'] = ($comment->status->value == COMMENT_NOT_PUBLISHED) ? 'unpublished' : 'published'; } // Gather comment classes. @@ -1649,7 +1659,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 == CommentInterface::PUBLISHED || user_access('administer comments')) { + if (user_access('access comments') && $entity->status->value == COMMENT_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 ce25a1c..800991f 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 == CommentInterface::PUBLISHED && user_access('edit own comments', $account)) || user_access('administer comments', $account); + return ($account->id() && $account->id() == $entity->uid->value && $entity->status->value == COMMENT_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 8a5d52f..d0066a8 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 : CommentInterface::NOT_PUBLISHED); + $status = (isset($comment->status->value) ? $comment->status->value : COMMENT_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') ? CommentInterface::PUBLISHED : CommentInterface::NOT_PUBLISHED); + $status = ($this->currentUser->hasPermission('skip comment approval') ? COMMENT_PUBLISHED : COMMENT_NOT_PUBLISHED); } $date = ''; @@ -195,8 +195,8 @@ public function form(array $form, array &$form_state) { '#title' => $this->t('Status'), '#default_value' => $status, '#options' => array( - CommentInterface::PUBLISHED => $this->t('Published'), - CommentInterface::NOT_PUBLISHED => $this->t('Not published'), + COMMENT_PUBLISHED => $this->t('Published'), + COMMENT_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 == CommentInterface::NOT_PUBLISHED) { + if ($comment->status->value == COMMENT_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 28ec9fb..fe7f40d 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentInterface.php +++ b/core/modules/comment/lib/Drupal/comment/CommentInterface.php @@ -16,16 +16,6 @@ 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. * * @return array diff --git a/core/modules/comment/lib/Drupal/comment/CommentStorageController.php b/core/modules/comment/lib/Drupal/comment/CommentStorageController.php index e23af78..0d93c65 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', CommentInterface::PUBLISHED) + ->condition('c.status', COMMENT_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', CommentInterface::PUBLISHED) + ->condition('c.status', COMMENT_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 4583f20..69ba909 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentStorageControllerInterface.php +++ b/core/modules/comment/lib/Drupal/comment/CommentStorageControllerInterface.php @@ -9,6 +9,7 @@ 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 dc4cd61..be9c41f 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 == CommentInterface::NOT_PUBLISHED && $entity->access('approve')) { + if ($entity->status->value == COMMENT_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 b1b127f..ccb3a4a 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 = CommentInterface::PUBLISHED; + $comment->status->value = COMMENT_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 == CommentInterface::NOT_PUBLISHED) || ($comment->entity_id->value != $entity->id())) { + if (($comment->status->value == COMMENT_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 d2c79bd..1b29d84 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') ? CommentInterface::PUBLISHED : CommentInterface::NOT_PUBLISHED; + $this->status->value = \Drupal::currentUser()->hasPermission('skip comment approval') ? COMMENT_PUBLISHED : COMMENT_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 == CommentInterface::PUBLISHED) { + if ($this->status->value == COMMENT_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 9c11291..93b9a99 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/Action/PublishComment.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/Action/PublishComment.php @@ -10,7 +10,6 @@ use Drupal\Core\Annotation\Action; use Drupal\Core\Annotation\Translation; use Drupal\Core\Action\ActionBase; -use Drupal\comment\CommentInterface; /** * Publishes a comment. @@ -27,7 +26,7 @@ class PublishComment extends ActionBase { * {@inheritdoc} */ public function execute($comment = NULL) { - $comment->status->value = CommentInterface::PUBLISHED; + $comment->status->value = COMMENT_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 f8350cc..b7d735e 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/Action/UnpublishByKeywordComment.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/Action/UnpublishByKeywordComment.php @@ -10,7 +10,6 @@ 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. @@ -31,7 +30,7 @@ public function execute($comment = NULL) { $text = drupal_render($build); foreach ($this->configuration['keywords'] as $keyword) { if (strpos($text, $keyword) !== FALSE) { - $comment->status->value = CommentInterface::NOT_PUBLISHED; + $comment->status->value = COMMENT_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 29a0b97..4857d3e 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/Action/UnpublishComment.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/Action/UnpublishComment.php @@ -10,7 +10,6 @@ use Drupal\Core\Annotation\Action; use Drupal\Core\Annotation\Translation; use Drupal\Core\Action\ActionBase; -use Drupal\comment\CommentInterface; /** * Unpublishes a comment. @@ -27,7 +26,7 @@ class UnpublishComment extends ActionBase { * {@inheritdoc} */ public function execute($comment = NULL) { - $comment->status->value = CommentInterface::NOT_PUBLISHED; + $comment->status->value = COMMENT_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 83ebc37..13ce3d0 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,7 +9,6 @@ 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; @@ -36,7 +35,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', CommentInterface::PUBLISHED); + $query->condition('status', COMMENT_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 6344b9e..5fd785a 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,7 +7,6 @@ namespace Drupal\comment\Plugin\views\field; -use Drupal\comment\CommentInterface; use Drupal\views\ResultRow; use Drupal\Component\Annotation\PluginID; @@ -40,7 +39,7 @@ protected function renderLink($data, ResultRow $values) { $status = $this->getValue($values, 'status'); // Don't show an approve link on published nodes. - if ($status == CommentInterface::PUBLISHED) { + if ($status == COMMENT_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 270136e..3ce1d29 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,7 +9,6 @@ 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; @@ -122,7 +121,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' => CommentInterface::PUBLISHED, + ':status' => COMMENT_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 ea892c8..94a1651 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentActionsTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentActionsTest.php @@ -7,8 +7,6 @@ namespace Drupal\comment\Tests; -use Drupal\comment\CommentInterface; - /** * Tests actions provided by the Comment module. */ @@ -41,12 +39,12 @@ function testCommentPublishUnpublishActions() { // Unpublish a comment. $action = entity_load('action', 'comment_unpublish_action'); $action->execute(array($comment)); - $this->assertEqual($comment->status->value, CommentInterface::NOT_PUBLISHED, 'Comment was unpublished'); + $this->assertEqual($comment->status->value, COMMENT_NOT_PUBLISHED, 'Comment was unpublished'); // Publish a comment. $action = entity_load('action', 'comment_publish_action'); $action->execute(array($comment)); - $this->assertEqual($comment->status->value, CommentInterface::PUBLISHED, 'Comment was published'); + $this->assertEqual($comment->status->value, COMMENT_PUBLISHED, 'Comment was published'); } /** @@ -72,10 +70,10 @@ function testCommentUnpublishByKeyword() { // Load the full comment so that status is available. $comment = comment_load($comment->id()); - $this->assertTrue($comment->status->value == CommentInterface::PUBLISHED, 'The comment status was set to published.'); + $this->assertTrue($comment->status->value == COMMENT_PUBLISHED, 'The comment status was set to published.'); $action->execute(array($comment)); - $this->assertTrue($comment->status->value == CommentInterface::NOT_PUBLISHED, 'The comment status was set to not published.'); + $this->assertTrue($comment->status->value == COMMENT_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 91b9d45..1e98287 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentCSSTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentCSSTest.php @@ -8,7 +8,6 @@ namespace Drupal\comment\Tests; use Drupal\Core\Language\Language; -use Drupal\comment\CommentInterface; /** * Tests comment CSS classes. @@ -41,7 +40,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(CommentInterface::PUBLISHED, CommentInterface::NOT_PUBLISHED), + 'comment_status' => array(COMMENT_PUBLISHED, COMMENT_NOT_PUBLISHED), 'user' => array('anonymous', 'authenticated', 'admin'), ); $permutations = $this->generatePermutations($parameters); @@ -91,7 +90,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'] == CommentInterface::PUBLISHED || $case['user'] == 'admin') { + if ($case['comment_status'] == COMMENT_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) { @@ -120,7 +119,7 @@ function testCommentClasses() { // Verify the unpublished class. $comments = $this->xpath('//*[contains(@class, "comment") and contains(@class, "unpublished")]'); - if ($case['comment_status'] == CommentInterface::NOT_PUBLISHED && $case['user'] == 'admin') { + if ($case['comment_status'] == COMMENT_NOT_PUBLISHED && $case['user'] == 'admin') { $this->assertTrue(count($comments) == 1, 'unpublished class found.'); } else { @@ -131,7 +130,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'] == CommentInterface::PUBLISHED || $case['user'] == 'admin') { + if ($case['comment_status'] == COMMENT_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 1e13ddb..b0311cb 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentInterfaceTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentInterfaceTest.php @@ -7,8 +7,6 @@ namespace Drupal\comment\Tests; -use Drupal\comment\CommentInterface; - /** * Tests the comment module administrative and end-user-facing interfaces. */ @@ -148,7 +146,7 @@ function testCommentInterface() { $this->setCommentsPerPage(50); // Attempt to reply to an unpublished comment. - $reply_loaded->status->value = CommentInterface::NOT_PUBLISHED; + $reply_loaded->status->value = COMMENT_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 6eabd64..c529ab9 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentLinksTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentLinksTest.php @@ -8,7 +8,6 @@ namespace Drupal\comment\Tests; use Drupal\Core\Language\Language; -use Drupal\comment\CommentInterface; /** * Tests comment links based on environment configurations. @@ -147,7 +146,7 @@ function setEnvironment(array $info) { 'field_name' => 'comment', 'pid' => 0, 'uid' => 0, - 'status' => CommentInterface::PUBLISHED, + 'status' => COMMENT_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 17e358c..cdf658a 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentNewIndicatorTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentNewIndicatorTest.php @@ -8,7 +8,6 @@ namespace Drupal\comment\Tests; use Drupal\Core\Language\Language; -use Drupal\comment\CommentInterface; /** * Tests the 'new' marker on comments. @@ -95,7 +94,7 @@ public function testCommentNewCommentsIndicator() { 'field_name' => 'comment', 'pid' => 0, 'uid' => $this->loggedInUser->id(), - 'status' => CommentInterface::PUBLISHED, + 'status' => COMMENT_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 3fb6460..98373ae 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,7 +9,6 @@ use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Language\Language; -use Drupal\comment\CommentInterface; use Drupal\simpletest\WebTestBase; /** @@ -408,7 +407,7 @@ public function testCommentHandler() { 'uid' => 1, 'cid' => NULL, 'pid' => 0, - 'status' => CommentInterface::PUBLISHED, + 'status' => COMMENT_PUBLISHED, 'subject' => 'Comment Published <&>', 'language' => Language::LANGCODE_NOT_SPECIFIED, ), @@ -419,7 +418,7 @@ public function testCommentHandler() { 'uid' => 1, 'cid' => NULL, 'pid' => 0, - 'status' => CommentInterface::NOT_PUBLISHED, + 'status' => COMMENT_NOT_PUBLISHED, 'subject' => 'Comment Unpublished <&>', 'language' => Language::LANGCODE_NOT_SPECIFIED, ), @@ -430,7 +429,7 @@ public function testCommentHandler() { 'uid' => 1, 'cid' => NULL, 'pid' => 0, - 'status' => CommentInterface::NOT_PUBLISHED, + 'status' => COMMENT_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 5c530c7..cdf9a5e 100644 --- a/core/modules/forum/lib/Drupal/forum/ForumManager.php +++ b/core/modules/forum/lib/Drupal/forum/ForumManager.php @@ -11,7 +11,6 @@ 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; @@ -519,14 +518,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' => CommentInterface::PUBLISHED, + ':status' => COMMENT_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' => CommentInterface::PUBLISHED, + ':status' => COMMENT_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 fed1353..d1f0e65 100644 --- a/core/modules/forum/lib/Drupal/forum/Tests/ForumUninstallTest.php +++ b/core/modules/forum/lib/Drupal/forum/Tests/ForumUninstallTest.php @@ -7,7 +7,6 @@ namespace Drupal\forum\Tests; -use Drupal\comment\CommentInterface; use Drupal\simpletest\WebTestBase; /** @@ -63,7 +62,7 @@ function testForumUninstallWithField() { 'field_name' => 'comment_forum', 'pid' => 0, 'uid' => 0, - 'status' => CommentInterface::PUBLISHED, + 'status' => COMMENT_PUBLISHED, 'subject' => $this->randomName(), 'hostname' => '127.0.0.1', )); diff --git a/core/modules/image/image.module b/core/modules/image/image.module index 5b0d9a3..52c4d53 100644 --- a/core/modules/image/image.module +++ b/core/modules/image/image.module @@ -420,12 +420,10 @@ function image_entity_presave(EntityInterface $entity, $type) { return; } - if (!empty($entity->settings['default_image']['fid'][0])) { - $entity->settings['default_image']['fid'] = $entity->settings['default_image']['fid'][0]; - } - if ($fid = $entity->settings['default_image']['fid']) { + $fid = $entity->settings['default_image']['fid']; + if ($fid) { $original_fid = isset($entity->original) ? $entity->original->settings['default_image']['fid'] : NULL; - if ($fid != $original_fid) { + if ($entity->settings['default_image']['fid'] != $original_fid) { $image = \Drupal::service('image.factory')->get(file_load($fid)->getFileUri()); $entity->settings['default_image']['width'] = $image->getWidth(); $entity->settings['default_image']['height'] = $image->getHeight(); @@ -454,15 +452,10 @@ function image_field_entity_update(FieldInterface $field) { $prior_field = $field->original; // The value of a managed_file element can be an array if #extended == TRUE. - $fid_new = isset($field->settings['default_image']['fid']['fids']) ? $field->settings['default_image']['fid']['fids'] : $field->settings['default_image']['fid']; - $fid_old = isset($prior_field->settings['default_image']['fid']['fids']) ? $prior_field->settings['default_image']['fid']['fids'] : $prior_field->settings['default_image']['fid']; - // Ensure that $fid_new and $fid_old are arrays, because the field setting - // 'default_image' key 'fid' might be the fallback value 0, see the annotation - // block of \Drupal\image\Plugin\Field\FieldType\ImageItem. - $fid_old = (array) $fid_old; - $fid_new = (array) $fid_new; + $fid_new = $field->settings['default_image']['fid']; + $fid_old = $prior_field->settings['default_image']['fid']; - $file_new = $fid_new ? file_load(reset($fid_new)) : FALSE; + $file_new = $fid_new ? file_load($fid_new) : FALSE; if ($fid_new != $fid_old) { @@ -474,7 +467,7 @@ function image_field_entity_update(FieldInterface $field) { } // Is there an old file? - if ($fid_old && ($file_old = file_load(reset($fid_old)))) { + if ($fid_old && ($file_old = file_load($fid_old))) { \Drupal::service('file.usage')->delete($file_old, 'image', 'default_image', $field->uuid); } } @@ -499,19 +492,11 @@ function image_field_instance_update(FieldInstanceInterface $field_instance) { $prior_instance = $field_instance->original; - // The value of a managed_file element can be an array if the #extended - // property is set to TRUE. $fid_new = $field_instance->settings['default_image']['fid']; - if (isset($fid_new['fids'])) { - $fid_new = $fid_new['fids']; - } $fid_old = $prior_instance->settings['default_image']['fid']; - if (isset($fid_old['fids'])) { - $fid_old = $fid_old['fids']; - } // If the old and new files do not match, update the default accordingly. - $file_new = $fid_new ? file_load($fid_new[0]) : FALSE; + $file_new = $fid_new ? file_load($fid_new) : FALSE; if ($fid_new != $fid_old) { // Save the new file, if present. if ($file_new) { @@ -520,7 +505,7 @@ function image_field_instance_update(FieldInstanceInterface $field_instance) { \Drupal::service('file.usage')->add($file_new, 'image', 'default_image', $field_instance->uuid); } // Delete the old file, if present. - if ($fid_old && ($file_old = file_load($fid_old[0]))) { + if ($fid_old && ($file_old = file_load($fid_old))) { \Drupal::service('file.usage')->delete($file_old, 'image', 'default_image', $field_instance->uuid); } } @@ -543,8 +528,8 @@ function image_field_entity_delete(FieldInterface $field) { } // The value of a managed_file element can be an array if #extended == TRUE. - $fid = (isset($field->settings['default_image']['fid']['fids']) ? $field->settings['default_image']['fid']['fids'] : $field->settings['default_image']['fid']); - if ($fid && ($file = file_load($fid[0]))) { + $fid = $field->settings['default_image']['fid']; + if ($fid && ($file = file_load($fid))) { \Drupal::service('file.usage')->delete($file, 'image', 'default_image', $field->uuid); } } @@ -559,12 +544,8 @@ function image_field_instance_delete(FieldInstanceInterface $field_instance) { return; } - // The value of a managed_file element can be an array if the #extended - // property is set to TRUE. + // The value of a managed_file element can be an array if #extended == TRUE. $fid = $field_instance->settings['default_image']['fid']; - if (is_array($fid)) { - $fid = $fid['fid']; - } // Remove the default image when the instance is deleted. if ($fid && ($file = file_load($fid))) { diff --git a/core/modules/image/lib/Drupal/image/Plugin/Field/FieldType/ImageItem.php b/core/modules/image/lib/Drupal/image/Plugin/Field/FieldType/ImageItem.php index b1e56f3..a8ef483 100644 --- a/core/modules/image/lib/Drupal/image/Plugin/Field/FieldType/ImageItem.php +++ b/core/modules/image/lib/Drupal/image/Plugin/Field/FieldType/ImageItem.php @@ -335,6 +335,7 @@ protected function defaultImageForm(array &$element, array $settings) { '#description' => t('Image to be shown if no image is uploaded.'), '#default_value' => empty($settings['default_image']['fid']) ? array() : array($settings['default_image']['fid']), '#upload_location' => $settings['uri_scheme'] . '://default_images/', + '#element_validate' => array(array($this, 'validateDefaultImageForm')), ); $element['default_image']['alt'] = array( '#type' => 'textfield', @@ -361,6 +362,34 @@ protected function defaultImageForm(array &$element, array $settings) { } /** + * Validates the managed_file element for the default Image form. + * + * This function ensures the fid is a scalar value and not an array. It is + * assigned as a #element_validate callback in + * \Drupal\image\Plugin\Field\FieldType\ImageItem::defaultImageForm(). + * + * @param array $element + * The form element to process. + * @param array $form_state + * The form state. + */ + public function validateDefaultImageForm(array &$element, array &$form_state) { + // Call the original validator to ensure referencing an existing file is + // only allowed if there are existing references. + file_managed_file_validate($element, $form_state); + + // Consolidate the array value of this field to a single FID as #extended + // for default image is not TRUE and this is a single value. + if (isset($element['fids']['#value'][0])) { + $value = $element['fids']['#value'][0]; + } + else { + $value = 0; + } + \Drupal::formBuilder()->setValue($element, $value, $form_state); + } + + /** * {@inheritdoc} */ public function isDisplayed() { diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageFieldDefaultImagesTest.php b/core/modules/image/lib/Drupal/image/Tests/ImageFieldDefaultImagesTest.php index da68885..8244fa0 100644 --- a/core/modules/image/lib/Drupal/image/Tests/ImageFieldDefaultImagesTest.php +++ b/core/modules/image/lib/Drupal/image/Tests/ImageFieldDefaultImagesTest.php @@ -33,6 +33,14 @@ public static function getInfo() { public function testDefaultImages() { // Create files to use as the default images. $files = $this->drupalGetTestFiles('image'); + // Create 10 files so the default image fids are not a single value. + for ($i = 1; $i <= 10; $i++) { + $filename = $this->randomName() . "$i"; + $desired_filepath = 'public://' . $filename; + file_unmanaged_copy($files[0]->uri, $desired_filepath, FILE_EXISTS_ERROR); + $file = entity_create('file', array('uri' => $desired_filepath, 'filename' => $filename, 'name' => $filename)); + $file->save(); + } $default_images = array(); foreach (array('field', 'instance', 'instance2', 'field_new', 'instance_new') as $image_target) { $file = entity_create('file', (array) array_pop($files)); @@ -173,7 +181,7 @@ public function testDefaultImages() { ); // Upload a new default for the field. - $field->settings['default_image']['fid'] = array($default_images['field_new']->id()); + $field->settings['default_image']['fid'] = $default_images['field_new']->id(); $field->save(); // Confirm that the new default is used on the article field settings form. diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeAccessPagerTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeAccessPagerTest.php index 74cd9c7..579626a 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeAccessPagerTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeAccessPagerTest.php @@ -8,7 +8,6 @@ namespace Drupal\node\Tests; use Drupal\Core\Language\Language; -use Drupal\comment\CommentInterface; use Drupal\simpletest\WebTestBase; /** @@ -56,7 +55,7 @@ public function testCommentPager() { 'comment_body' => array( array('value' => $this->randomName()), ), - 'status' => CommentInterface::PUBLISHED, + 'status' => COMMENT_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 8a96631..411f6fe 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Theme/EntityFilteringThemeTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Theme/EntityFilteringThemeTest.php @@ -7,7 +7,6 @@ namespace Drupal\system\Tests\Theme; -use Drupal\comment\CommentInterface; use Drupal\simpletest\WebTestBase; /** @@ -113,7 +112,7 @@ function setUp() { 'entity_id' => $this->node->id(), 'entity_type' => 'node', 'field_name' => 'comment', - 'status' => CommentInterface::PUBLISHED, + 'status' => COMMENT_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 0abd95e..7a3983e 100644 --- a/core/modules/tracker/lib/Drupal/tracker/Tests/TrackerTest.php +++ b/core/modules/tracker/lib/Drupal/tracker/Tests/TrackerTest.php @@ -7,7 +7,6 @@ namespace Drupal\tracker\Tests; -use Drupal\comment\CommentInterface; use Drupal\simpletest\WebTestBase; /** @@ -122,7 +121,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' => CommentInterface::NOT_PUBLISHED), t('Save')); + $this->drupalPostForm('comment/1/edit', array('status' => COMMENT_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 b1be041..eca8ccc 100644 --- a/core/modules/tracker/tracker.module +++ b/core/modules/tracker/tracker.module @@ -6,7 +6,6 @@ */ use Drupal\Core\Entity\EntityInterface; -use Drupal\comment\CommentInterface; use Drupal\node\NodeInterface; use Drupal\Core\Session\AccountInterface; @@ -93,7 +92,7 @@ function tracker_cron() { ->condition('c.entity_id', $row->nid) ->condition('c.entity_type', 'node') ->condition('c.uid', $row->uid, '<>') - ->condition('c.status', CommentInterface::PUBLISHED); + ->condition('c.status', COMMENT_PUBLISHED); // Insert the user-level data for the commenters (except if a commenter // is the node's author). @@ -194,7 +193,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 != CommentInterface::PUBLISHED && $comment->entity_type->value == 'node') { + if ($comment->status->value != COMMENT_PUBLISHED && $comment->entity_type->value == 'node') { _tracker_remove($comment->entity_id->target_id, $comment->uid->target_id, $comment->changed->value); } } @@ -286,7 +285,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' => CommentInterface::PUBLISHED, + ':status' => COMMENT_PUBLISHED, ), array('target' => 'slave'))->fetchObject(); if ($latest_comment && $latest_comment->changed > $changed) { $changed = $latest_comment->changed; @@ -320,7 +319,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' => CommentInterface::PUBLISHED, + ':status' => COMMENT_PUBLISHED, ))->fetchField(); }