Unverified Commit 397cd309 authored by alexpott's avatar alexpott

Issue #3006397 by Mile23, Lendude, alexpott, Berdir: Fix...

Issue #3006397 by Mile23, Lendude, alexpott, Berdir: Fix "Drupal\system\Plugin\views\field\BulkForm is deprecated in Drupal 8.5.x, will be removed before Drupal 9.0.0. Use \Drupal\views\Plugin\views\field\BulkForm instead." deprecation error
parent d95b4d72
......@@ -2,8 +2,9 @@
namespace Drupal\system\Plugin\views\field;
@trigger_error(__NAMESPACE__ . '\BulkForm is deprecated in Drupal 8.5.x, will be removed before Drupal 9.0.0. Use \Drupal\views\Plugin\views\field\BulkForm instead. See https://www.drupal.org/node/2916716.', E_USER_DEPRECATED);
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Messenger\MessengerInterface;
use Drupal\views\Plugin\views\field\BulkForm as ViewsBulkForm;
/**
......@@ -11,11 +12,19 @@
*
* @ViewsField("legacy_bulk_form")
*
* @deprecated in Drupal 8.5.x, will be removed before Drupal 9.0.0. Use
* @deprecated in drupal:8.5.0, will be removed before drupal:9.0.0. Use
* \Drupal\views\Plugin\views\field\BulkForm instead.
*
* @see https://www.drupal.org/node/2916716
*/
class BulkForm extends ViewsBulkForm {
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, LanguageManagerInterface $language_manager, MessengerInterface $messenger) {
@trigger_error(__NAMESPACE__ . '\BulkForm is deprecated in drupal:8.5.0, will be removed before drupal:9.0.0. Use \Drupal\views\Plugin\views\field\BulkForm instead. See https://www.drupal.org/node/2916716.', E_USER_DEPRECATED);
parent::__construct($configuration, $plugin_id, $plugin_definition, $entity_type_manager, $language_manager, $messenger);
}
}
......@@ -3,6 +3,7 @@
namespace Drupal\Tests\views\Kernel;
use Drupal\views\Views;
use Drupal\views\Plugin\views\PluginBase;
/**
* Tests that an instance of all views plugins can be created.
......@@ -38,6 +39,15 @@ class PluginInstanceTest extends ViewsKernelTestBase {
'wizard',
];
/**
* List of deprecated plugin classes.
*
* @var string[]
*/
protected $deprecatedPlugins = [
'Drupal\system\Plugin\views\field\BulkForm',
];
/**
* An array of plugin definitions, keyed by plugin type.
*
......@@ -69,25 +79,53 @@ public function testPluginData() {
$this->assertTrue(empty($diff), 'All plugins were found and matched.');
}
/**
* Tests creating instances of deprecated views plugin.
*
* This will iterate through all plugins from _views_fetch_plugin_data() and
* test only deprecated plugins.
*
* @group legacy
*
* @expectedDeprecation Drupal\system\Plugin\views\field\BulkForm is deprecated in drupal:8.5.0, will be removed before drupal:9.0.0. Use \Drupal\views\Plugin\views\field\BulkForm instead. See https://www.drupal.org/node/2916716.
*/
public function testDeprecatedPluginInstances() {
$this->assertPluginInstances(TRUE);
}
/**
* Tests creating instances of every views plugin.
*
* This will iterate through all plugins from _views_fetch_plugin_data().
* This will iterate through all plugins from _views_fetch_plugin_data(),
* filtering out deprecated plugins.
*/
public function testPluginInstances() {
$this->assertPluginInstances(FALSE);
}
/**
* Asserts that instances of every views plugin can be created.
*
* @param bool $test_deprecated
* Indicates if deprecated plugins should be tested or skipped.
*/
protected function assertPluginInstances($test_deprecated) {
foreach ($this->definitions as $type => $plugins) {
// Get a plugin manager for this type.
$manager = $this->container->get("plugin.manager.views.$type");
foreach ($plugins as $id => $definition) {
if ($test_deprecated !== in_array($definition['class'], $this->deprecatedPlugins)) {
continue;
}
// Get a reflection class for this plugin.
// We only want to test true plugins, i.e. They extend PluginBase.
$reflection = new \ReflectionClass($definition['class']);
if ($reflection->isSubclassOf('Drupal\views\Plugin\views\PluginBase')) {
if ($reflection->isSubclassOf(PluginBase::class)) {
// Create a plugin instance and check what it is. This is not just
// good to check they can be created but for throwing any notices for
// method signatures etc. too.
$instance = $manager->createInstance($id);
$this->assertTrue($instance instanceof $definition['class'], format_string('Instance of @type:@id created', ['@type' => $type, '@id' => $id]));
$this->assertInstanceOf($definition['class'], $instance);
}
}
}
......
......@@ -125,7 +125,6 @@ public static function getSkippedDeprecations() {
'The "plugin.manager.migrate.cckfield" service is deprecated. You should use the \'plugin.manager.migrate.field\' service instead. See https://www.drupal.org/node/2751897',
'The Drupal\editor\Plugin\EditorBase::settingsFormValidate method is deprecated since version 8.3.x and will be removed in 9.0.0.',
'The Drupal\migrate\Plugin\migrate\process\Migration is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, use Drupal\migrate\Plugin\migrate\process\MigrationLookup',
'Drupal\system\Plugin\views\field\BulkForm is deprecated in Drupal 8.5.x, will be removed before Drupal 9.0.0. Use \Drupal\views\Plugin\views\field\BulkForm instead. See https://www.drupal.org/node/2916716.',
'The numeric plugin for watchdog.wid field is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Must use standard plugin instead. See https://www.drupal.org/node/2876378.',
'Passing in arguments the legacy way is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Provide the right parameter names in the method, similar to controllers. See https://www.drupal.org/node/2894819',
'The Drupal\editor\Plugin\EditorBase::settingsFormSubmit method is deprecated since version 8.3.x and will be removed in 9.0.0.',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment