diff --git a/core/modules/comment/comment.admin.inc b/core/modules/comment/comment.admin.inc
index 99bb6b0..abbf800 100644
--- a/core/modules/comment/comment.admin.inc
+++ b/core/modules/comment/comment.admin.inc
@@ -41,7 +41,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 1491817..f1c5a0b 100644
--- a/core/modules/comment/comment.module
+++ b/core/modules/comment/comment.module
@@ -163,19 +163,13 @@ function comment_field_extra_fields() {
*/
function comment_theme() {
return array(
- 'comment_preview' => array(
- 'variables' => array('comment' => NULL),
- ),
'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',
),
);
}
@@ -514,13 +508,8 @@ function comment_entity_view(EntityInterface $entity, EntityViewDisplayInterface
}
}
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' => CommentManager::forbiddenMessage($entity, $field_name),
'html' => TRUE,
);
}
@@ -549,13 +538,8 @@ function comment_entity_view(EntityInterface $entity, EntityViewDisplayInterface
}
}
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' => CommentManager::forbiddenMessage($entity, $field_name),
'html' => TRUE,
);
}
@@ -1495,56 +1479,6 @@ function template_preprocess_comment(&$variables) {
}
/**
- * Returns HTML for a "you can't post comments" notice.
- *
- * @param $variables
- * An associative array containing:
- * - commented_entity: The entity to which comments are attached to.
- * - field_name: The comment field.
- *
- * @ingroup themeable
- */
-function theme_comment_post_forbidden($variables) {
- $entity = $variables['commented_entity'];
- $field_name = $variables['field_name'];
-
- // 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.
- $authenticated_post_comments = &drupal_static(__FUNCTION__, NULL);
-
- if (\Drupal::currentUser()->isAnonymous()) {
- if (!isset($authenticated_post_comments)) {
- // We only output a link if we are certain that users will get permission
- // to post comments by logging in.
- $comment_roles = user_roles(TRUE, 'post comments');
- $authenticated_post_comments = isset($comment_roles[DRUPAL_AUTHENTICATED_RID]);
- }
-
- if ($authenticated_post_comments) {
- $instance = \Drupal::service('field.info')->getInstance($entity->entityType(), $entity->bundle(), $field_name);
- // We cannot use drupal_get_destination() because these links
- // sometimes appear on /node and taxonomy listing pages.
- if ($instance->getSetting('form_location') == COMMENT_FORM_SEPARATE_PAGE) {
- $destination = array('destination' => 'comment/reply/' . $entity->entityType() . '/' . $entity->id() . '/' . $field_name . '#comment-form');
- }
- else {
- $uri = $entity->uri();
- $destination = array('destination' => $uri['path'] . '#comment-form');
- }
-
- if (\Drupal::config('user.settings')->get('register') != USER_REGISTER_ADMINISTRATORS_ONLY) {
- // Users can register themselves.
- return t('Log in or register to post comments', array('@login' => url('user/login', array('query' => $destination)), '@register' => url('user/register', array('query' => $destination))));
- }
- else {
- // Only admins can add new users, no public registration.
- return t('Log in to post comments', array('@login' => url('user/login', array('query' => $destination))));
- }
- }
- }
-}
-
-/**
* Prepares variables for comment wrapper templates.
*
* Default template: comment-wrapper.html.twig.
diff --git a/core/modules/comment/lib/Drupal/comment/CommentManager.php b/core/modules/comment/lib/Drupal/comment/CommentManager.php
index fc833b8..8ad96ff 100644
--- a/core/modules/comment/lib/Drupal/comment/CommentManager.php
+++ b/core/modules/comment/lib/Drupal/comment/CommentManager.php
@@ -200,4 +200,56 @@ public function getFieldUIPageTitle($commented_entity_type, $field_name) {
return String::checkPlain($sample_instance->label);
}
+ /**
+ * Provides a message if posting comments is forbidden.
+ *
+ * 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.
+ *
+ * @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.
+ */
+ static public function forbiddenMessage(EntityInterface $entity, $field_name) {
+ // 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.
+ $authenticated_post_comments = &drupal_static(__FUNCTION__, NULL);
+
+ if (\Drupal::currentUser()->isAnonymous()) {
+ if (!isset($authenticated_post_comments)) {
+ // We only output a link if we are certain that users will get permission
+ // to post comments by logging in.
+ $comment_roles = user_roles(TRUE, 'post comments');
+ $authenticated_post_comments = isset($comment_roles[DRUPAL_AUTHENTICATED_RID]);
+ }
+
+ if ($authenticated_post_comments) {
+ $instance = \Drupal::service('field.info')->getInstance($entity->entityType(), $entity->bundle(), $field_name);
+ // We cannot use drupal_get_destination() because these links
+ // sometimes appear on /node and taxonomy listing pages.
+ if ($instance->getSetting('form_location') == COMMENT_FORM_SEPARATE_PAGE) {
+ $destination = array('destination' => 'comment/reply/' . $entity->entityType() . '/' . $entity->id() . '/' . $field_name . '#comment-form');
+ }
+ else {
+ $uri = $entity->uri();
+ $destination = array('destination' => $uri['path'] . '#comment-form');
+ }
+
+ if (\Drupal::config('user.settings')->get('register') != USER_REGISTER_ADMINISTRATORS_ONLY) {
+ // Users can register themselves.
+ return t('Log in or register to post comments', array('@login' => url('user/login', array('query' => $destination)), '@register' => url('user/register', array('query' => $destination))));
+ }
+ else {
+ // Only admins can add new users, no public registration.
+ return t('Log in to post comments', array('@login' => url('user/login', array('query' => $destination))));
+ }
+ }
+ }
+ }
+
}
diff --git a/core/modules/comment/lib/Drupal/comment/CommentViewBuilder.php b/core/modules/comment/lib/Drupal/comment/CommentViewBuilder.php
index dc4cd61..ba82de2 100644
--- a/core/modules/comment/lib/Drupal/comment/CommentViewBuilder.php
+++ b/core/modules/comment/lib/Drupal/comment/CommentViewBuilder.php
@@ -240,12 +240,7 @@ protected static function buildLinks(CommentInterface $entity, EntityInterface $
);
}
if (empty($links)) {
- $comment_post_forbidden = array(
- '#theme' => 'comment_post_forbidden',
- '#commented_entity' => $commented_entity,
- '#field_name' => $entity->field_name->value,
- );
- $links['comment-forbidden']['title'] = drupal_render($comment_post_forbidden);
+ $links['comment-forbidden']['title'] = CommentManager::forbiddenMessage($commented_entity, $entity->field_name->value);
$links['comment-forbidden']['html'] = TRUE;
}
}
diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentLinksTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentLinksTest.php
index 6eabd64..770633c 100644
--- a/core/modules/comment/lib/Drupal/comment/Tests/CommentLinksTest.php
+++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentLinksTest.php
@@ -260,7 +260,7 @@ function assertCommentLinks(array $info) {
// Anonymous users should see a note to log in or register in case
// authenticated users are allowed to post comments.
- // @see theme_comment_post_forbidden()
+ // @see CommentManager::forbiddenMessage()
if (!$this->loggedInUser) {
if (user_access('post comments', $this->web_user)) {
// The note depends on whether users are actually able to register.