diff --git a/core/modules/comment/comment.install b/core/modules/comment/comment.install index f71a7e4..758c6db 100644 --- a/core/modules/comment/comment.install +++ b/core/modules/comment/comment.install @@ -29,7 +29,7 @@ function comment_uninstall() { variable_del('comment_subject_field_' . $node_type); } - // Remove states. + // Remove state setting. \Drupal::state()->delete('comment.node_comment_statistics_scale'); } diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 64fe92b..4baec94 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -9,14 +9,12 @@ * book page, etc. */ -use Drupal\node\NodeTypeInterface; +use Drupal\Core\Entity\EntityInterface; +use Drupal\comment\CommentInterface; use Drupal\entity\Entity\EntityDisplay; use Drupal\file\Entity\File; -use Drupal\Core\Entity\EntityInterface; use Drupal\node\NodeInterface; -use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; -use Symfony\Component\HttpKernel\HttpKernelInterface; +use Drupal\node\NodeTypeInterface; /** * Comment is awaiting approval. @@ -78,8 +76,6 @@ */ const COMMENT_NODE_OPEN = 2; -use Drupal\comment\Entity\Comment; - /** * Implements hook_help(). */ @@ -118,7 +114,7 @@ function comment_entity_bundle_info() { /** * Entity URI callback. */ -function comment_uri(Comment $comment) { +function comment_uri(CommentInterface $comment) { return array( 'path' => 'comment/' . $comment->id(), 'options' => array('fragment' => 'comment-' . $comment->id()), @@ -376,10 +372,10 @@ function comment_permission() { /** * Finds the most recent comments that are available to the current user. * - * @param integer $number + * @param int $number * (optional) The maximum number of comments to find. Defaults to 10. * - * @return + * @return array * An array of comment objects or an empty array if there are no recent * comments visible to the current user. */ @@ -409,15 +405,15 @@ function comment_get_recent($number = 10) { /** * Calculates the page number for the first new comment. * - * @param $num_comments + * @param int $num_comments * Number of comments. - * @param $new_replies + * @param int $new_replies * Number of new replies. * @param \Drupal\Core\Entity\EntityInterface $node * The first new comment node. * - * @return - * "page=X" if the page number is greater than zero; empty string otherwise. + * @return array|NULL + * Array "page=X" if the page number is greater than zero; NULL otherwise. */ function comment_new_page_count($num_comments, $new_replies, EntityInterface $node) { $mode = variable_get('comment_default_mode_' . $node->getType(), COMMENT_MODE_THREADED); @@ -633,7 +629,7 @@ function comment_node_view_alter(&$build, EntityInterface $node, EntityDisplay $ * @param \Drupal\Core\Entity\EntityInterface $node * The node entity for which to build the comment-related elements. * - * @return + * @return array * A renderable array representing the comment-related page elements for the * node. */ @@ -695,12 +691,12 @@ function comment_add(EntityInterface $node, $pid = NULL) { * * @param \Drupal\Core\Entity\EntityInterface $node * The node whose comment(s) needs rendering. - * @param $mode + * @param int $mode * The comment display mode; COMMENT_MODE_FLAT or COMMENT_MODE_THREADED. - * @param $comments_per_page + * @param int $comments_per_page * The amount of comments to display per page. * - * @return + * @return array * An array of the IDs of the comment to be displayed. * * To display threaded comments in the correct order we keep a 'thread' field @@ -813,7 +809,7 @@ function comment_prepare_thread(&$comments) { // A counter that helps track how indented we are. $divs = 0; - foreach ($comments as $key => $comment) { + foreach ($comments as $key => &$comment) { // The $divs element instructs #prefix whether to add an indent div or // close existing divs (a negative value). $comment->depth = count(explode('.', $comment->thread->value)) - 1; @@ -827,7 +823,6 @@ function comment_prepare_thread(&$comments) { $divs--; } } - $comments[$key] = $comment; } // The final comment must close up some hanging divs @@ -837,33 +832,33 @@ function comment_prepare_thread(&$comments) { /** * Generates an array for rendering a comment. * - * @param Drupal\comment\Comment $comment + * @param \Drupal\comment\CommentInterface $comment * The comment object. * @param $view_mode - * View mode, e.g. 'full', 'teaser'... + * (optional) View mode, e.g. 'full', 'teaser'... Defaults to 'full'. * @param $langcode * (optional) A language code to use for rendering. Defaults to the global * content language of the current request. * - * @return + * @return array * An array as expected by drupal_render(). */ -function comment_view(Comment $comment, $view_mode = 'full', $langcode = NULL) { +function comment_view(CommentInterface $comment, $view_mode = 'full', $langcode = NULL) { return entity_view($comment, $view_mode, $langcode); } /** * Adds reply, edit, delete, etc. links, depending on user permissions. * - * @param Drupal\comment\Comment $comment + * @param \Drupal\comment\CommentInterface $comment * The comment object. * @param \Drupal\Core\Entity\EntityInterface $node * The node the comment is attached to. * - * @return + * @return array * A structured array of links. */ -function comment_links(Comment $comment, EntityInterface $node) { +function comment_links(CommentInterface $comment, EntityInterface $node) { $links = array(); if ($node->comment->value == COMMENT_NODE_OPEN) { if ($comment->access('delete')) { @@ -925,10 +920,11 @@ function comment_links(Comment $comment, EntityInterface $node) { * @param $view_mode * View mode, e.g. 'full', 'teaser'... * @param $langcode - * A string indicating the language field values are to be shown in. If no - * language is provided the current content language is used. + * (optional) A string indicating the language field values are to be shown + * in. If no language is provided the current content language is used. + * Defaults to NULL. * - * @return + * @return array * An array in the format expected by drupal_render(). * * @see drupal_render() @@ -1294,7 +1290,7 @@ function comment_load_multiple(array $cids = NULL, $reset = FALSE) { * @param bool $reset * (optional) Whether to reset the internal static entity cache. * - * @return + * @return \Drupal\comment\CommentInterface * The comment object. */ function comment_load($cid, $reset = FALSE) { @@ -1304,13 +1300,12 @@ function comment_load($cid, $reset = FALSE) { /** * Gets the number of new comments for the current user and the specified node. * - * @param $nid + * @param int $nid * Node ID to count comments for. - * @param $timestamp - * Time to count from (defaults to time of last user access - * to node). + * @param int $timestamp + * Time to count from (defaults to time of last user access to node). * - * @return + * @return int|FALSE * The number of new comments or FALSE if the user is not logged in. */ function comment_num_new($nid, $timestamp = 0) { @@ -1342,12 +1337,12 @@ function comment_num_new($nid, $timestamp = 0) { * Count the number of comments which appear before the comment we want to * display, taking into account display settings and threading. * - * @param $cid + * @param int $cid * The comment ID. - * @param $node_type + * @param string $node_type * The node type of the comment's parent. * - * @return + * @return int * The display ordinal for the comment. * * @see comment_get_display_page() @@ -1386,12 +1381,12 @@ function comment_get_display_ordinal($cid, $node_type) { * Finds the correct page number for a comment taking into account display * and paging settings. * - * @param $cid + * @param int $cid * The comment ID. - * @param $node_type + * @param string $node_type * The node type the comment is attached to. * - * @return + * @return int * The page number. */ function comment_get_display_page($cid, $node_type) { @@ -1403,9 +1398,13 @@ function comment_get_display_page($cid, $node_type) { /** * Generates a comment preview. * - * @param Drupal\comment\Comment $comment + * @param \Drupal\comment\CommentInterface $comment + * The comment entity to preview. + * + * @return array + * An array as expected by drupal_render(). */ -function comment_preview(Comment $comment) { +function comment_preview(CommentInterface $comment) { global $user; $preview_build = array(); @@ -1467,10 +1466,13 @@ function comment_preprocess_block(&$variables) { * This helper handles anonymous authors in addition to registered comment * authors. * - * @return \Drupal\user\Entity\User + * @param \Drupal\comment\CommentInterface $comment + * The comment to which the author replied. + * + * @return \Drupal\user\UserInterface * A user account, for use with theme_username() or the user_picture template. */ -function comment_prepare_author(Comment $comment) { +function comment_prepare_author(CommentInterface $comment) { // The account has been pre-loaded by CommentRenderController::buildContent(). $account = $comment->uid->entity; if (empty($account->uid->value)) { diff --git a/core/modules/comment/comment.views.inc b/core/modules/comment/comment.views.inc index 79602d2..796b776 100644 --- a/core/modules/comment/comment.views.inc +++ b/core/modules/comment/comment.views.inc @@ -98,7 +98,7 @@ function comment_views_data() { 'help' => t('Hostname of user that posted the comment.'), 'field' => array( 'id' => 'standard', - ), + ), 'filter' => array( 'id' => 'string', ), @@ -115,7 +115,7 @@ function comment_views_data() { 'help' => t('E-mail of user that posted the comment. Will be empty if the author is a registered user.'), 'field' => array( 'id' => 'standard', - ), + ), 'filter' => array( 'id' => 'string', ), diff --git a/core/modules/comment/lib/Drupal/comment/CommentInterface.php b/core/modules/comment/lib/Drupal/comment/CommentInterface.php index 456b957..fb9c043 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentInterface.php +++ b/core/modules/comment/lib/Drupal/comment/CommentInterface.php @@ -24,4 +24,5 @@ * UrlGenerator::generateFromPath(). */ public function permalink(); + } diff --git a/core/modules/comment/lib/Drupal/comment/CommentStorageController.php b/core/modules/comment/lib/Drupal/comment/CommentStorageController.php index 6068ce9..b1dece7 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentStorageController.php +++ b/core/modules/comment/lib/Drupal/comment/CommentStorageController.php @@ -9,7 +9,6 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\DatabaseStorageControllerNG; -use Drupal\Component\Uuid\Uuid; /** * Defines the controller class for comments. @@ -43,10 +42,9 @@ protected function buildQuery($ids, $revision_id = FALSE) { */ protected function attachLoad(&$records, $load_revision = FALSE) { // Prepare standard comment fields. - foreach ($records as $key => $record) { + foreach ($records as $key => &$record) { $record->name = $record->uid ? $record->registered_name : $record->name; $record->node_type = 'comment_node_' . $record->node_type; - $records[$key] = $record; } parent::attachLoad($records, $load_revision); } @@ -126,4 +124,5 @@ public function getChildCids(array $comments) { ->execute() ->fetchCol(); } + } diff --git a/core/modules/comment/lib/Drupal/comment/Controller/CommentController.php b/core/modules/comment/lib/Drupal/comment/Controller/CommentController.php index 48a23cd..dc2c35d 100644 --- a/core/modules/comment/lib/Drupal/comment/Controller/CommentController.php +++ b/core/modules/comment/lib/Drupal/comment/Controller/CommentController.php @@ -8,11 +8,10 @@ namespace Drupal\comment\Controller; use Drupal\comment\CommentInterface; -use Drupal\comment\Entity\Comment; +use Drupal\node\NodeInterface; use Drupal\Core\Access\CsrfTokenGenerator; use Drupal\Core\Controller\ControllerBase; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; -use Drupal\Node\NodeInterface; use Drupal\Core\Session\AccountInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\JsonResponse; @@ -242,7 +241,7 @@ public function getReplyForm(Request $request, NodeInterface $node, $pid = NULL) * @param \Symfony\Component\HttpFoundation\Request $request * The request of the page. * - * @return Symfony\Component\HttpFoundation\JsonResponse + * @return \Symfony\Component\HttpFoundation\JsonResponse * The JSON response. */ public function renderNewCommentsNodeLinks(Request $request) { diff --git a/core/modules/comment/lib/Drupal/comment/Entity/Comment.php b/core/modules/comment/lib/Drupal/comment/Entity/Comment.php index d46fb3d..e437fd57 100644 --- a/core/modules/comment/lib/Drupal/comment/Entity/Comment.php +++ b/core/modules/comment/lib/Drupal/comment/Entity/Comment.php @@ -55,7 +55,7 @@ class Comment extends EntityNG implements CommentInterface { /** * The comment ID. * - * @todo Rename to 'id'. + * @todo Rename to 'id'. https://drupal.org/node/2031935 * * @var \Drupal\Core\Entity\Field\FieldInterface */ @@ -69,9 +69,9 @@ class Comment extends EntityNG implements CommentInterface { public $uuid; /** - * The parent comment ID if this is a reply to a comment. + * The parent comment ID if this is a reply to another comment. * - * @todo: Rename to 'parent_id'. + * @todo: Rename to 'parent_id'. https://drupal.org/node/2031931 * * @var \Drupal\Core\Entity\Field\FieldInterface */ diff --git a/core/modules/comment/lib/Drupal/comment/Form/DeleteForm.php b/core/modules/comment/lib/Drupal/comment/Form/DeleteForm.php index 53e1741..cd07a0b 100644 --- a/core/modules/comment/lib/Drupal/comment/Form/DeleteForm.php +++ b/core/modules/comment/lib/Drupal/comment/Form/DeleteForm.php @@ -9,7 +9,6 @@ use Drupal\Core\Cache\Cache; use Drupal\Core\Entity\EntityNGConfirmFormBase; -use Symfony\Component\HttpFoundation\Request; /** * Provides the comment delete confirmation form.