Loading core/modules/comment/src/CommentLinkBuilder.php +5 −6 Original line number Diff line number Diff line Loading @@ -2,7 +2,6 @@ namespace Drupal\comment; use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Session\AccountInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; Loading Loading @@ -94,7 +93,7 @@ public function buildCommentedEntityLinks(FieldableEntityInterface $entity, arra } // Provide a link to new comment form. if ($commenting_status == CommentingStatus::Open) { $comment_form_location = $field_definition->getSetting('form_location'); $comment_form_location = FormLocation::tryFrom((int) $field_definition->getSetting('form_location')); if ($this->currentUser->hasPermission('post comments')) { $links['comment-add'] = [ 'title' => $this->t('Add new comment'), Loading @@ -102,7 +101,7 @@ public function buildCommentedEntityLinks(FieldableEntityInterface $entity, arra 'attributes' => ['title' => $this->t('Share your thoughts and opinions.')], 'fragment' => 'comment-form', ]; if ($comment_form_location == CommentItemInterface::FORM_SEPARATE_PAGE) { if ($comment_form_location == FormLocation::SeparatePage) { $links['comment-add']['url'] = Url::fromRoute('comment.reply', [ 'entity_type' => $entity->getEntityTypeId(), 'entity' => $entity->id(), Loading @@ -125,17 +124,17 @@ public function buildCommentedEntityLinks(FieldableEntityInterface $entity, arra // is allowed to post comments and if this entity is allowing new // comments. if ($commenting_status == CommentingStatus::Open) { $comment_form_location = $field_definition->getSetting('form_location'); $comment_form_location = FormLocation::tryFrom((int) $field_definition->getSetting('form_location')); if ($this->currentUser->hasPermission('post comments')) { // Show the "post comment" link if the form is on another page, or // if there are existing comments that the link will skip past. if ($comment_form_location == CommentItemInterface::FORM_SEPARATE_PAGE || (!empty($entity->get($field_name)->comment_count) && $this->currentUser->hasPermission('access comments'))) { if ($comment_form_location == FormLocation::SeparatePage || (!empty($entity->get($field_name)->comment_count) && $this->currentUser->hasPermission('access comments'))) { $links['comment-add'] = [ 'title' => $this->t('Add new comment'), 'attributes' => ['title' => $this->t('Share your thoughts and opinions.')], 'fragment' => 'comment-form', ]; if ($comment_form_location == CommentItemInterface::FORM_SEPARATE_PAGE) { if ($comment_form_location == FormLocation::SeparatePage) { $links['comment-add']['url'] = Url::fromRoute('comment.reply', [ 'entity_type' => $entity->getEntityTypeId(), 'entity' => $entity->id(), Loading core/modules/comment/src/CommentManager.php +1 −2 Original line number Diff line number Diff line Loading @@ -2,7 +2,6 @@ namespace Drupal\comment; use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Entity\EntityDisplayRepositoryInterface; use Drupal\Core\Entity\EntityFieldManagerInterface; Loading Loading @@ -163,7 +162,7 @@ public function forbiddenMessage(EntityInterface $entity, $field_name) { if ($this->authenticatedCanPostComments) { // We cannot use the redirect.destination service here because these links // sometimes appear on /node and taxonomy listing pages. if ($entity->get($field_name)->getFieldDefinition()->getSetting('form_location') == CommentItemInterface::FORM_SEPARATE_PAGE) { if ($entity->get($field_name)->getFieldDefinition()->getSetting('form_location') == FormLocation::SeparatePage->value) { $comment_reply_parameters = [ 'entity_type' => $entity->getEntityTypeId(), 'entity' => $entity->id(), Loading core/modules/comment/src/FormLocation.php 0 → 100644 +18 −0 Original line number Diff line number Diff line <?php declare(strict_types=1); namespace Drupal\comment; /** * Options for comment form display. */ enum FormLocation: int { // Comment form should be displayed on a separate page. case SeparatePage = 0; // Comment form should be shown below post or list of comments. case Below = 1; } core/modules/comment/src/Plugin/Field/FieldFormatter/CommentDefaultFormatter.php +3 −2 Original line number Diff line number Diff line Loading @@ -3,7 +3,7 @@ namespace Drupal\comment\Plugin\Field\FieldFormatter; use Drupal\comment\CommentingStatus; use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; use Drupal\comment\FormLocation; use Drupal\Core\Entity\Entity\EntityViewDisplay; use Drupal\Core\Entity\EntityDisplayRepositoryInterface; use Drupal\Core\Entity\EntityFormBuilderInterface; Loading Loading @@ -167,7 +167,8 @@ public function viewElements(FieldItemListInterface $items, $langcode) { // Append comment form if the comments are open and the form is set to // display below the entity. Do not show the form for the print view mode. if ($status == CommentingStatus::Open && $comment_settings['form_location'] == CommentItemInterface::FORM_BELOW && $this->viewMode != 'print') { $form_location = FormLocation::tryFrom($comment_settings['form_location']); if ($status == CommentingStatus::Open && $form_location == FormLocation::Below && $this->viewMode != 'print') { // Only show the add comment form if the user has permission. $elements['#cache']['contexts'][] = 'user.roles'; if ($this->currentUser->hasPermission('post comments')) { Loading core/modules/comment/src/Plugin/Field/FieldType/CommentItem.php +2 −1 Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ use Drupal\comment\CommentManagerInterface; use Drupal\comment\CommentPreviewMode; use Drupal\comment\Entity\CommentType; use Drupal\comment\FormLocation; use Drupal\Core\Field\Attribute\FieldType; use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldItemBase; Loading Loading @@ -48,7 +49,7 @@ public static function defaultFieldSettings() { return [ 'default_mode' => CommentManagerInterface::COMMENT_MODE_THREADED, 'per_page' => 50, 'form_location' => CommentItemInterface::FORM_BELOW, 'form_location' => FormLocation::Below->value, 'anonymous' => AnonymousContact::Forbidden->value, 'preview' => CommentPreviewMode::Optional->value, ] + parent::defaultFieldSettings(); Loading Loading
core/modules/comment/src/CommentLinkBuilder.php +5 −6 Original line number Diff line number Diff line Loading @@ -2,7 +2,6 @@ namespace Drupal\comment; use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Session\AccountInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; Loading Loading @@ -94,7 +93,7 @@ public function buildCommentedEntityLinks(FieldableEntityInterface $entity, arra } // Provide a link to new comment form. if ($commenting_status == CommentingStatus::Open) { $comment_form_location = $field_definition->getSetting('form_location'); $comment_form_location = FormLocation::tryFrom((int) $field_definition->getSetting('form_location')); if ($this->currentUser->hasPermission('post comments')) { $links['comment-add'] = [ 'title' => $this->t('Add new comment'), Loading @@ -102,7 +101,7 @@ public function buildCommentedEntityLinks(FieldableEntityInterface $entity, arra 'attributes' => ['title' => $this->t('Share your thoughts and opinions.')], 'fragment' => 'comment-form', ]; if ($comment_form_location == CommentItemInterface::FORM_SEPARATE_PAGE) { if ($comment_form_location == FormLocation::SeparatePage) { $links['comment-add']['url'] = Url::fromRoute('comment.reply', [ 'entity_type' => $entity->getEntityTypeId(), 'entity' => $entity->id(), Loading @@ -125,17 +124,17 @@ public function buildCommentedEntityLinks(FieldableEntityInterface $entity, arra // is allowed to post comments and if this entity is allowing new // comments. if ($commenting_status == CommentingStatus::Open) { $comment_form_location = $field_definition->getSetting('form_location'); $comment_form_location = FormLocation::tryFrom((int) $field_definition->getSetting('form_location')); if ($this->currentUser->hasPermission('post comments')) { // Show the "post comment" link if the form is on another page, or // if there are existing comments that the link will skip past. if ($comment_form_location == CommentItemInterface::FORM_SEPARATE_PAGE || (!empty($entity->get($field_name)->comment_count) && $this->currentUser->hasPermission('access comments'))) { if ($comment_form_location == FormLocation::SeparatePage || (!empty($entity->get($field_name)->comment_count) && $this->currentUser->hasPermission('access comments'))) { $links['comment-add'] = [ 'title' => $this->t('Add new comment'), 'attributes' => ['title' => $this->t('Share your thoughts and opinions.')], 'fragment' => 'comment-form', ]; if ($comment_form_location == CommentItemInterface::FORM_SEPARATE_PAGE) { if ($comment_form_location == FormLocation::SeparatePage) { $links['comment-add']['url'] = Url::fromRoute('comment.reply', [ 'entity_type' => $entity->getEntityTypeId(), 'entity' => $entity->id(), Loading
core/modules/comment/src/CommentManager.php +1 −2 Original line number Diff line number Diff line Loading @@ -2,7 +2,6 @@ namespace Drupal\comment; use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Entity\EntityDisplayRepositoryInterface; use Drupal\Core\Entity\EntityFieldManagerInterface; Loading Loading @@ -163,7 +162,7 @@ public function forbiddenMessage(EntityInterface $entity, $field_name) { if ($this->authenticatedCanPostComments) { // We cannot use the redirect.destination service here because these links // sometimes appear on /node and taxonomy listing pages. if ($entity->get($field_name)->getFieldDefinition()->getSetting('form_location') == CommentItemInterface::FORM_SEPARATE_PAGE) { if ($entity->get($field_name)->getFieldDefinition()->getSetting('form_location') == FormLocation::SeparatePage->value) { $comment_reply_parameters = [ 'entity_type' => $entity->getEntityTypeId(), 'entity' => $entity->id(), Loading
core/modules/comment/src/FormLocation.php 0 → 100644 +18 −0 Original line number Diff line number Diff line <?php declare(strict_types=1); namespace Drupal\comment; /** * Options for comment form display. */ enum FormLocation: int { // Comment form should be displayed on a separate page. case SeparatePage = 0; // Comment form should be shown below post or list of comments. case Below = 1; }
core/modules/comment/src/Plugin/Field/FieldFormatter/CommentDefaultFormatter.php +3 −2 Original line number Diff line number Diff line Loading @@ -3,7 +3,7 @@ namespace Drupal\comment\Plugin\Field\FieldFormatter; use Drupal\comment\CommentingStatus; use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; use Drupal\comment\FormLocation; use Drupal\Core\Entity\Entity\EntityViewDisplay; use Drupal\Core\Entity\EntityDisplayRepositoryInterface; use Drupal\Core\Entity\EntityFormBuilderInterface; Loading Loading @@ -167,7 +167,8 @@ public function viewElements(FieldItemListInterface $items, $langcode) { // Append comment form if the comments are open and the form is set to // display below the entity. Do not show the form for the print view mode. if ($status == CommentingStatus::Open && $comment_settings['form_location'] == CommentItemInterface::FORM_BELOW && $this->viewMode != 'print') { $form_location = FormLocation::tryFrom($comment_settings['form_location']); if ($status == CommentingStatus::Open && $form_location == FormLocation::Below && $this->viewMode != 'print') { // Only show the add comment form if the user has permission. $elements['#cache']['contexts'][] = 'user.roles'; if ($this->currentUser->hasPermission('post comments')) { Loading
core/modules/comment/src/Plugin/Field/FieldType/CommentItem.php +2 −1 Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ use Drupal\comment\CommentManagerInterface; use Drupal\comment\CommentPreviewMode; use Drupal\comment\Entity\CommentType; use Drupal\comment\FormLocation; use Drupal\Core\Field\Attribute\FieldType; use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldItemBase; Loading Loading @@ -48,7 +49,7 @@ public static function defaultFieldSettings() { return [ 'default_mode' => CommentManagerInterface::COMMENT_MODE_THREADED, 'per_page' => 50, 'form_location' => CommentItemInterface::FORM_BELOW, 'form_location' => FormLocation::Below->value, 'anonymous' => AnonymousContact::Forbidden->value, 'preview' => CommentPreviewMode::Optional->value, ] + parent::defaultFieldSettings(); Loading