Verified Commit 979d45e3 authored by godotislate's avatar godotislate
Browse files

refactor: #3547353 Move HIDDEN, CLOSED and OPEN constants in...

refactor: #3547353 Move HIDDEN, CLOSED and OPEN constants in CommentItemInterface to new CommentingStatus enum

By: mstrelan
By: smustgrave
By: godotislate
parent 43c31284
Loading
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -17457,6 +17457,14 @@
	'count' => 1,
	'path' => __DIR__ . '/modules/history/src/Controller/HistoryController.php',
];
$ignoreErrors[] = [
	'message' => '#^Fetching deprecated class constant HIDDEN of interface Drupal\\\\comment\\\\Plugin\\\\Field\\\\FieldType\\\\CommentItemInterface\\:
in drupal\\:11\\.4\\.0 and is removed from drupal\\:13\\.0\\.0\\.
  Use \\\\Drupal\\\\comment\\\\CommentingStatus\\:\\:Hidden instead\\.$#',
	'identifier' => 'classConstant.deprecated',
	'count' => 1,
	'path' => __DIR__ . '/modules/history/src/HistoryCommentLinkBuilder.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\history\\\\Plugin\\\\views\\\\field\\\\HistoryUserTimestamp\\:\\:buildOptionsForm\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
@@ -25887,6 +25895,22 @@
	'count' => 1,
	'path' => __DIR__ . '/modules/node/tests/src/Kernel/Migrate/d7/MigrateNodeRevisionTest.php',
];
$ignoreErrors[] = [
	'message' => '#^Fetching deprecated class constant CLOSED of interface Drupal\\\\comment\\\\Plugin\\\\Field\\\\FieldType\\\\CommentItemInterface\\:
in drupal\\:11\\.4\\.0 and is removed from drupal\\:13\\.0\\.0\\.
  Use \\\\Drupal\\\\comment\\\\CommentingStatus\\:\\:Closed instead\\.$#',
	'identifier' => 'classConstant.deprecated',
	'count' => 3,
	'path' => __DIR__ . '/modules/node/tests/src/Kernel/Migrate/d7/MigrateNodeTest.php',
];
$ignoreErrors[] = [
	'message' => '#^Fetching deprecated class constant OPEN of interface Drupal\\\\comment\\\\Plugin\\\\Field\\\\FieldType\\\\CommentItemInterface\\:
in drupal\\:11\\.4\\.0 and is removed from drupal\\:13\\.0\\.0\\.
  Use \\\\Drupal\\\\comment\\\\CommentingStatus\\:\\:Open instead\\.$#',
	'identifier' => 'classConstant.deprecated',
	'count' => 4,
	'path' => __DIR__ . '/modules/node/tests/src/Kernel/Migrate/d7/MigrateNodeTest.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Tests\\\\node\\\\Kernel\\\\Migrate\\\\d7\\\\MigrateNodeTest\\:\\:fileMigrationSetup\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
+2 −3
Original line number Diff line number Diff line
@@ -2,7 +2,6 @@

namespace Drupal\comment;

use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Entity\EntityAccessControlHandler;
use Drupal\Core\Entity\EntityInterface;
@@ -109,9 +108,9 @@ protected function checkFieldAccess($operation, FieldDefinitionInterface $field_
        if ($commented_entity && $comment_field_name) {
          // We are creating a new comment, user can edit create only fields if
          // commenting is open.
          $commenting_status = (int) $commented_entity->get($comment_field_name)->status;
          $commenting_status = CommentingStatus::tryFrom((int) $commented_entity->get($comment_field_name)->status);
          $access_result = $access_result
            ->andIf(AccessResult::allowedIf($commenting_status !== CommentItemInterface::CLOSED))
            ->andIf(AccessResult::allowedIf($commenting_status !== CommentingStatus::Closed))
            ->addCacheableDependency($commented_entity);
        }
        return $access_result;
+2 −3
Original line number Diff line number Diff line
@@ -2,7 +2,6 @@

namespace Drupal\comment;

use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\Component\Datetime\TimeInterface;
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\Unicode;
@@ -393,7 +392,7 @@ public function preview(array &$form, FormStateInterface $form_state) {
      // field output.
      $field_name = $comment->getFieldName();
      $entity = clone $entity;
      $entity->$field_name->status = CommentItemInterface::HIDDEN;
      $entity->$field_name->status = CommentingStatus::Hidden->value;
      $build = $this->entityTypeManager
        ->getViewBuilder($entity->getEntityTypeId())
        ->view($entity);
@@ -418,7 +417,7 @@ public function save(array $form, FormStateInterface $form_state) {
    $uri = $entity->toUrl();
    $logger = $this->logger('comment');

    if ($this->currentUser->hasPermission('post comments') && ($this->currentUser->hasPermission('administer comments') || $entity->{$field_name}->status == CommentItemInterface::OPEN)) {
    if ($this->currentUser->hasPermission('post comments') && ($this->currentUser->hasPermission('administer comments') || $entity->{$field_name}->status == CommentingStatus::Open->value)) {
      $comment->save();
      $form_state->setValue('cid', $comment->id());

+2 −3
Original line number Diff line number Diff line
@@ -2,7 +2,6 @@

namespace Drupal\comment;

use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\Core\Entity\EntityFormBuilderInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
@@ -174,9 +173,9 @@ public function renderLinks($comment_entity_id, $view_mode, $langcode, $is_in_pr
   */
  protected function buildLinks(CommentInterface $entity, EntityInterface $commented_entity) {
    $links = [];
    $status = $commented_entity->get($entity->getFieldName())->status;
    $status = CommentingStatus::tryFrom((int) $commented_entity->get($entity->getFieldName())->status);

    if ($status == CommentItemInterface::OPEN) {
    if ($status == CommentingStatus::Open) {
      if ($entity->access('delete')) {
        $links['comment-delete'] = [
          'title' => $this->t('Delete'),
+4 −4
Original line number Diff line number Diff line
@@ -97,8 +97,8 @@ public function buildCommentedEntityLinks(FieldableEntityInterface $entity, arra
        continue;
      }
      $links = [];
      $commenting_status = $entity->get($field_name)->status;
      if ($commenting_status != CommentItemInterface::HIDDEN) {
      $commenting_status = CommentingStatus::tryFrom((int) $entity->get($field_name)->status);
      if ($commenting_status != CommentingStatus::Hidden) {
        // Entity has commenting status open or closed.
        $field_definition = $entity->getFieldDefinition($field_name);
        if ($view_mode == 'teaser') {
@@ -116,7 +116,7 @@ public function buildCommentedEntityLinks(FieldableEntityInterface $entity, arra
            }
          }
          // Provide a link to new comment form.
          if ($commenting_status == CommentItemInterface::OPEN) {
          if ($commenting_status == CommentingStatus::Open) {
            $comment_form_location = $field_definition->getSetting('form_location');
            if ($this->currentUser->hasPermission('post comments')) {
              $links['comment-add'] = [
@@ -147,7 +147,7 @@ public function buildCommentedEntityLinks(FieldableEntityInterface $entity, arra
          // Entity in other view modes: add a "post comment" link if the user
          // is allowed to post comments and if this entity is allowing new
          // comments.
          if ($commenting_status == CommentItemInterface::OPEN) {
          if ($commenting_status == CommentingStatus::Open) {
            $comment_form_location = $field_definition->getSetting('form_location');
            if ($this->currentUser->hasPermission('post comments')) {
              // Show the "post comment" link if the form is on another page, or
Loading