diff --git a/core/modules/comment/comment.admin.inc b/core/modules/comment/comment.admin.inc index 2013de8..cf6191a 100644 --- a/core/modules/comment/comment.admin.inc +++ b/core/modules/comment/comment.admin.inc @@ -39,7 +39,6 @@ function comment_admin($type = 'new') { * @see comment_admin() * @see comment_admin_overview_validate() * @see comment_admin_overview_submit() - * @see theme_comment_admin_overview() */ function comment_admin_overview($form, &$form_state, $arg) { // Build an 'Update options' form. diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 9f8b282..a71fad2 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -175,20 +175,15 @@ function comment_theme() { return array( 'comment_block' => array( 'variables' => array('number' => NULL), - ), - 'comment_preview' => array( - 'variables' => array('comment' => NULL), + 'template' => 'comment-block', ), 'comment' => array( - 'template' => 'comment', 'render element' => 'elements', - ), - 'comment_post_forbidden' => array( - 'variables' => array('commented_entity' => NULL, 'field_name' => 'comment'), + 'template' => 'comment', ), 'comment_wrapper' => array( - 'template' => 'comment-wrapper', 'render element' => 'content', + 'template' => 'comment-wrapper', ), ); } @@ -440,26 +435,23 @@ function comment_new_page_count($num_comments, $new_replies, EntityInterface $en } /** - * Returns HTML for a list of recent comments. + * Prepares variables for comment block templates. * - * @ingroup themeable + * Default template: comment-block.html.twig. + * + * @param array $variables + * An associative array containing: + * - number: The number of recent comments to display. */ -function theme_comment_block($variables) { - $items = array(); +function template_preprocess_comment_block(&$variables) { + $variables['comments'] = array(); $number = $variables['number']; foreach (comment_get_recent($number) as $comment) { - $items[] = l($comment->subject, 'comment/' . $comment->cid, array('fragment' => 'comment-' . $comment->cid)) . ' ' . t('@time ago', array('@time' => format_interval(REQUEST_TIME - $comment->changed))) . ''; - } - - if ($items) { - $item_list = array( - '#theme' => 'item_list', - '#items' => $items, + $variables['comments'][] = array( + 'data' => $comment, + 'link' => l($comment->subject, 'comment/' . $comment->cid, array('fragment' => 'comment-' . $comment->cid)), + 'time' => format_interval(REQUEST_TIME - $comment->changed), ); - return drupal_render($item_list); - } - else { - return t('No comments available.'); } } @@ -541,13 +533,8 @@ function comment_entity_view(EntityInterface $entity, EntityDisplay $display, $v } } else { - $comment_post_forbidden = array( - '#theme' => 'comment_post_forbidden', - '#commented_entity' => $entity, - '#field_name' => $field_name, - ); $links['comment-forbidden'] = array( - 'title' => drupal_render($comment_post_forbidden), + 'title' => comment_forbidden_message($entity, $field_name), 'html' => TRUE, ); } @@ -576,13 +563,8 @@ function comment_entity_view(EntityInterface $entity, EntityDisplay $display, $v } } else { - $comment_post_forbidden = array( - '#theme' => 'comment_post_forbidden', - '#commented_entity' => $entity, - '#field_name' => $field_name, - ); $links['comment-forbidden'] = array( - 'title' => drupal_render($comment_post_forbidden), + 'title' => comment_forbidden_message($entity, $field_name), 'html' => TRUE, ); } @@ -1512,19 +1494,23 @@ function template_preprocess_comment(&$variables) { } /** - * Returns HTML for a "you can't post comments" notice. + * Provides a message if posting comments is forbidden. * - * @param $variables - * An associative array containing: - * - commented_entity: The entity to which comments are attached to. - * - field_name: The comment field. + * If authenticated users can post comments, a message is returned that prompts + * the anonymous user to log in (or register, if applicable) that redirects to + * entity comment form. Otherwise, no message is returned. * - * @ingroup themeable + * @param \Drupal\Core\Entity\EntityInterface $entity + * The entity to which comments are attached to. + * @param string $field_name + * The field name on the entity to which comments are attached to. + * + * @return + * HTML for a "you can't post comments" notice. */ -function theme_comment_post_forbidden($variables) { - $entity = $variables['commented_entity']; - $field_name = $variables['field_name']; - global $user; +function comment_forbidden_message(EntityInterface $entity, $field_name) { + + $user = \Drupal::currentUser(); // Since this is expensive to compute, we cache it so that a page with many // comments only has to query the database once for all the links. diff --git a/core/modules/comment/templates/comment-block.html.twig b/core/modules/comment/templates/comment-block.html.twig new file mode 100644 index 0000000..13f7816 --- /dev/null +++ b/core/modules/comment/templates/comment-block.html.twig @@ -0,0 +1,24 @@ +{# +/** + * @file + * Default theme implementation for a list of recent comments. + * + * Available variables: + * - comments: A list of recent comments. + * + * @see template_preprocess_comment_block() + * + * @ingroup themeable + */ +#} +{% if comments %} + +{% else %} + {{ 'No comments available.'|t }} +{% endif %}