Unverified Commit ad34608a authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3187435 by Spokje, Pooja Ganjage, raman.b, alexpott, daffie: Deprecate...

Issue #3187435 by Spokje, Pooja Ganjage, raman.b, alexpott, daffie: Deprecate $database argument in \Drupal\node\Plugin\views\argument\Vid::__construct()
parent 8fafcd34
Loading
Loading
Loading
Loading
+13 −10
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@

namespace Drupal\node\Plugin\views\argument;

use Drupal\Core\Database\Connection;
use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait;
use Drupal\views\Plugin\views\argument\NumericArgument;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\node\NodeStorageInterface;
@@ -14,12 +14,12 @@
 */
class Vid extends NumericArgument {

  use DeprecatedServicePropertyTrait;

  /**
   * Database Service Object.
   *
   * @var \Drupal\Core\Database\Connection
   * {@inheritdoc}
   */
  protected $database;
  protected $deprecatedProperties = ['database' => 'database'];

  /**
   * The node storage.
@@ -37,15 +37,19 @@ class Vid extends NumericArgument {
   *   The plugin_id for the plugin instance.
   * @param mixed $plugin_definition
   *   The plugin implementation definition.
   * @param \Drupal\Core\Database\Connection $database
   *   Database Service Object.
   * @param \Drupal\node\NodeStorageInterface $node_storage
   *   The node storage.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, Connection $database, NodeStorageInterface $node_storage) {
  public function __construct(array $configuration, $plugin_id, $plugin_definition, $node_storage) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);

    $this->database = $database;
    if (!$node_storage instanceof NodeStorageInterface) {
      @trigger_error('Passing the database service to ' . __METHOD__ . '() is deprecated in drupal:9.2.0 and will be removed before drupal:10.0.0. See https://www.drupal.org/node/3178412', E_USER_DEPRECATED);
      $node_storage = func_get_arg(4);
    }
    if (!$node_storage instanceof NodeStorageInterface) {
      throw new \InvalidArgumentException('The fourth argument must implement \Drupal\node\NodeStorageInterface.');
    }
    $this->nodeStorage = $node_storage;
  }

@@ -57,7 +61,6 @@ public static function create(ContainerInterface $container, array $configuratio
      $configuration,
      $plugin_id,
      $plugin_definition,
      $container->get('database'),
      $container->get('entity_type.manager')->getStorage('node')
    );
  }
+14 −0
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@

use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\node\Plugin\views\argument\Vid;
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
use Drupal\views\Tests\ViewTestData;
use Drupal\views\Views;
@@ -54,4 +55,17 @@ public function testNodeRevisionRelationship() {
    $this->assertIdenticalResultset($view_nid, [['title' => 'test2']]);
  }

  /**
   * Tests the Vid argument deprecation.
   *
   * @group legacy
   */
  public function testVidDeprecatedParameter() {
    $this->expectDeprecation('Passing the database service to Drupal\node\Plugin\views\argument\Vid::__construct() is deprecated in drupal:9.2.0 and will be removed before drupal:10.0.0. See https://www.drupal.org/node/3178412');
    $database = $this->container->get('database');
    $node_storage = $this->container->get('entity_type.manager')->getStorage('node');
    $vid = new Vid([], 'test_plugin', [], $database, $node_storage);
    $this->assertNotNull($vid);
  }

}