Issue #3187435 by Spokje, Pooja Ganjage, raman.b, alexpott, daffie: Deprecate $database argument in \Drupal\node\Plugin\views\argument\Vid::__construct()

merge-requests/184/head
Alex Pott 2020-12-22 12:51:41 +00:00
parent 8fafcd342e
commit ad34608ab0
No known key found for this signature in database
GPG Key ID: 31905460D4A69276
2 changed files with 27 additions and 10 deletions

View File

@ -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 @@ use Drupal\node\NodeStorageInterface;
*/
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 @@ class Vid extends NumericArgument {
$configuration,
$plugin_id,
$plugin_definition,
$container->get('database'),
$container->get('entity_type.manager')->getStorage('node')
);
}

View File

@ -4,6 +4,7 @@ namespace Drupal\Tests\node\Kernel\Views;
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 @@ class ArgumentNodeRevisionIdTest extends ViewsKernelTestBase {
$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);
}
}