diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index bb203bf..b9d84e4 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -661,11 +661,17 @@ function template_preprocess_comment(&$variables) { else { $uri = $comment->permalink(); $attributes = $uri->getOption('attributes') ?: []; - $attributes += ['class' => ['permalink'], 'rel' => 'bookmark']; + $attributes += ['class' => ['permalink']]; + if (CommentType::load($comment->bundle())->getNofollow()) { + $attributes += ['rel' => 'bookmark nofollow']; + } + else { + $attributes += ['rel' => 'bookmark']; + } $uri->setOption('attributes', $attributes); $variables['title'] = \Drupal::l($comment->getSubject(), $uri); - $variables['permalink'] = \Drupal::l(t('Permalink'), $comment->permalink()); + $variables['permalink'] = \Drupal::l(t('Permalink'), $uri); } $variables['submitted'] = t('Submitted by @username on @datetime', ['@username' => $variables['author'], '@datetime' => $variables['created']]); @@ -690,7 +696,13 @@ function template_preprocess_comment(&$variables) { } $permalink_uri_parent = $comment_parent->permalink(); $attributes = $permalink_uri_parent->getOption('attributes') ?: []; - $attributes += ['class' => ['permalink'], 'rel' => 'bookmark']; + $attributes += ['class' => ['permalink']]; + if (CommentType::load($comment_parent->bundle())->getNofollow()) { + $attributes += ['rel' => 'bookmark nofollow']; + } + else { + $attributes += ['rel' => 'bookmark']; + } $permalink_uri_parent->setOption('attributes', $attributes); $variables['parent_title'] = \Drupal::l($comment_parent->getSubject(), $permalink_uri_parent); $variables['parent_permalink'] = \Drupal::l(t('Parent permalink'), $permalink_uri_parent); diff --git a/core/modules/comment/config/schema/comment.schema.yml b/core/modules/comment/config/schema/comment.schema.yml index 045e9ad..a344f10 100644 --- a/core/modules/comment/config/schema/comment.schema.yml +++ b/core/modules/comment/config/schema/comment.schema.yml @@ -58,6 +58,9 @@ comment.type.*: description: type: text label: 'Description' + nofollow: + type: boolean + label: 'Rel nofollow' field.storage_settings.comment: type: mapping diff --git a/core/modules/comment/src/CommentTypeForm.php b/core/modules/comment/src/CommentTypeForm.php index 0ac5b44..64033b7 100644 --- a/core/modules/comment/src/CommentTypeForm.php +++ b/core/modules/comment/src/CommentTypeForm.php @@ -122,6 +122,13 @@ public function form(array $form, FormStateInterface $form_state) { ]; } + $form['nofollow'] = [ + '#type' => 'checkbox', + '#title' => t('Nofollow'), + '#default_value' => $comment_type->getNofollow(), + '#description' => t('Add nofollow to rel attribute of comment type.'), + ]; + if ($this->moduleHandler->moduleExists('content_translation')) { $form['language'] = [ '#type' => 'details', diff --git a/core/modules/comment/src/CommentTypeInterface.php b/core/modules/comment/src/CommentTypeInterface.php index acde96c..4653576 100644 --- a/core/modules/comment/src/CommentTypeInterface.php +++ b/core/modules/comment/src/CommentTypeInterface.php @@ -35,4 +35,11 @@ public function setDescription($description); */ public function getTargetEntityTypeId(); + /** + * Gets the setting of rel's nofollow for this comment type. + * + * @return bool + * TRUE if the comment type has the rel set to nofollow, FALSE otherwise. + */ + public function getNofollow(); } diff --git a/core/modules/comment/src/Entity/CommentType.php b/core/modules/comment/src/Entity/CommentType.php index a773c58..62009db 100644 --- a/core/modules/comment/src/Entity/CommentType.php +++ b/core/modules/comment/src/Entity/CommentType.php @@ -44,6 +44,7 @@ * "label", * "target_entity_type_id", * "description", + * "nofollow", * } * ) */ @@ -78,6 +79,13 @@ class CommentType extends ConfigEntityBundleBase implements CommentTypeInterface protected $target_entity_type_id; /** + * Whether the comment type has rel set to nofollow. + * + * @var bool + */ + protected $nofollow = TRUE; + + /** * {@inheritdoc} */ public function getDescription() { @@ -99,4 +107,11 @@ public function getTargetEntityTypeId() { return $this->target_entity_type_id; } + /** + * {@inheritdoc} + */ + public function getNofollow() { + return $this->nofollow; + } + }