Verified Commit 5a8f40da authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3442365 by catch, Sandeep Sanwale: Removed deprecated code in taxonomy module

parent 6d733889
Loading
Loading
Loading
Loading
Loading
+2 −20
Original line number Diff line number Diff line
@@ -2,7 +2,6 @@

namespace Drupal\taxonomy\Plugin\views\argument;

use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
@@ -25,28 +24,11 @@
class IndexTidDepth extends ArgumentPluginBase implements ContainerFactoryPluginInterface {
  use TaxonomyIndexDepthQueryTrait;

  /**
   * @var \Drupal\Core\Entity\EntityStorageInterface
   *
   * @deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. There is no
   *   replacement.
   *
   * @see https://www.drupal.org/node/3427843
   */
  protected $termStorage;

  /**
   * {@inheritdoc}
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, protected EntityStorageInterface|EntityRepositoryInterface $entityRepository) {
  public function __construct(array $configuration, $plugin_id, $plugin_definition, protected EntityRepositoryInterface $entityRepository) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);

    if ($entityRepository instanceof EntityStorageInterface) {
      // @phpstan-ignore-next-line
      $this->termStorage = $entityRepository;
      @trigger_error('Calling ' . __CLASS__ . '::__construct() with the $termStorage argument as \Drupal\Core\Entity\EntityStorageInterface is deprecated in drupal:10.3.0 and it will require Drupal\Core\Entity\EntityRepositoryInterface in drupal:11.0.0. See https://www.drupal.org/node/3427843', E_USER_DEPRECATED);
      $this->entityRepository = \Drupal::service('entity.repository');
    }
  }

  /**
@@ -129,7 +111,7 @@ public function title() {
    if (!empty($term)) {
      return $term->label();
    }
    // TODO review text
    // @todo review text
    return $this->t('No name');
  }

+1 −18
Original line number Diff line number Diff line
@@ -3,7 +3,6 @@
namespace Drupal\taxonomy\Plugin\views\argument;

use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\views\Attribute\ViewsArgument;
use Drupal\views\Plugin\views\argument\NumericArgument;
@@ -19,27 +18,11 @@
)]
class Taxonomy extends NumericArgument implements ContainerFactoryPluginInterface {

  /**
   * @var \Drupal\Core\Entity\EntityStorageInterface
   *
   * @deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. There is no
   *   replacement.
   *
   * @see https://www.drupal.org/node/3427843
   */
  protected $termStorage;

  /**
   * {@inheritdoc}
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, protected EntityStorageInterface|EntityRepositoryInterface $entityRepository) {
  public function __construct(array $configuration, $plugin_id, $plugin_definition, protected EntityRepositoryInterface $entityRepository) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    if ($entityRepository instanceof EntityStorageInterface) {
      // @phpstan-ignore-next-line
      $this->termStorage = $this->entityRepository;
      @trigger_error('Calling ' . __CLASS__ . '::__construct() with the $termStorage argument as \Drupal\Core\Entity\EntityStorageInterface is deprecated in drupal:10.3.0 and it will require Drupal\Core\Entity\EntityRepositoryInterface in drupal:11.0.0. See https://www.drupal.org/node/3427843', E_USER_DEPRECATED);
      $this->entityRepository = \Drupal::service('entity.repository');
    }
  }

  /**
+0 −38
Original line number Diff line number Diff line
<?php

declare(strict_types=1);

namespace Drupal\Tests\taxonomy\Kernel\Views;

use Drupal\KernelTests\KernelTestBase;
use Drupal\taxonomy_test\Plugin\views\argument\TaxonomyViewsArgumentTest;

/**
 * Tests deprecation messages in views argument plugins.
 *
 * @group taxonomy
 */
class ViewsArgumentDeprecationTest extends KernelTestBase {

  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'system',
    'taxonomy',
    'taxonomy_test',
    'views',
  ];

  /**
   * Test the deprecation message in ViewsArgument plugin.
   *
   * @group legacy
   */
  public function testDeprecation(): void {
    $this->expectDeprecation('Calling Drupal\taxonomy\Plugin\views\argument\Taxonomy::__construct() with the $termStorage argument as \Drupal\Core\Entity\EntityStorageInterface is deprecated in drupal:10.3.0 and it will require Drupal\Core\Entity\EntityRepositoryInterface in drupal:11.0.0. See https://www.drupal.org/node/3427843');
    $plugin = \Drupal::service('plugin.manager.views.argument')->createInstance('taxonomy_views_argument_test', []);
    $this->assertInstanceOf(TaxonomyViewsArgumentTest::class, $plugin);
  }

}