Verified Commit 29703278 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3437579 by andypost: Remove deprecated code from comment module

parent 572e3275
Loading
Loading
Loading
Loading
Loading
+2 −9
Original line number Diff line number Diff line
@@ -60,7 +60,7 @@ class CommentStatistics implements CommentStatisticsInterface {
   *   The entity type manager.
   * @param \Drupal\Core\State\StateInterface $state
   *   The state service.
   * @param \Drupal\Component\Datetime\TimeInterface|null|\Drupal\Core\Database\Connection $time
   * @param \Drupal\Component\Datetime\TimeInterface $time
   *   The time service.
   * @param \Drupal\Core\Database\Connection|null $database_replica
   *   (Optional) the replica database connection.
@@ -70,20 +70,13 @@ public function __construct(
    AccountInterface $current_user,
    EntityTypeManagerInterface $entity_type_manager,
    StateInterface $state,
    protected TimeInterface|Connection|null $time = NULL,
    protected TimeInterface $time,
    Connection $database_replica = NULL,
  ) {
    $this->database = $database;
    $this->currentUser = $current_user;
    $this->entityTypeManager = $entity_type_manager;
    $this->state = $state;
    if (!$time || $time instanceof Connection) {
      @trigger_error('Calling ' . __METHOD__ . '() without the $time argument is deprecated in drupal:10.3.0 and it will be the 4th argument in drupal:11.0.0. See https://www.drupal.org/node/3387233', E_USER_DEPRECATED);
      if ($time instanceof Connection) {
        $database_replica = $time;
      }
      $this->time = \Drupal::service(TimeInterface::class);
    }
    $this->databaseReplica = $database_replica ?: $database;
  }

+0 −27
Original line number Diff line number Diff line
<?php

namespace Drupal\comment\Plugin\Action;

use Drupal\action\Plugin\Action\UnpublishByKeywordComment as ActionUnpublishByKeywordComment;
use Drupal\Core\Entity\EntityViewBuilderInterface;
use Drupal\Core\Render\RendererInterface;

/**
 * Unpublishes a comment containing certain keywords.
 *
 * @deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. Use
 *  \Drupal\action\Plugin\Action\UnpublishByKeywordComment instead.
 *
 * @see https://www.drupal.org/node/3424506
 */
class UnpublishByKeywordComment extends ActionUnpublishByKeywordComment {

  /**
   * {@inheritdoc}
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityViewBuilderInterface $comment_view_builder, RendererInterface $renderer) {
    @trigger_error(__CLASS__ . ' is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. Use \Drupal\action\Plugin\Action\UnpublishByKeywordComment instead. See https://www.drupal.org/node/3424506', E_USER_DEPRECATED);
    parent::__construct($configuration, $plugin_id, $plugin_definition, $comment_view_builder, $renderer);
  }

}
+0 −28
Original line number Diff line number Diff line
<?php

declare(strict_types=1);

namespace Drupal\Tests\comment\Unit\Action;

use Drupal\comment\Plugin\Action\UnpublishByKeywordComment;
use Drupal\Core\Entity\EntityViewBuilderInterface;
use Drupal\Core\Render\RendererInterface;
use Drupal\Tests\UnitTestCase;

/**
 * @group comment
 * @group legacy
 */
class UnpublishByKeywordCommentTest extends UnitTestCase {

  /**
   * Tests deprecation message.
   */
  public function testUnpublishByKeywordAction() {
    $comment_view_builder = $this->createMock(EntityViewBuilderInterface::class);
    $renderer = $this->createMock(RendererInterface::class);
    $this->expectDeprecation('Drupal\comment\Plugin\Action\UnpublishByKeywordComment is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. Use \Drupal\action\Plugin\Action\UnpublishByKeywordComment instead. See https://www.drupal.org/node/3424506');
    $this->assertIsObject(new UnpublishByKeywordComment([], 'foo', [], $comment_view_builder, $renderer));
  }

}