diff --git a/core/lib/Drupal/Component/Plugin/PluginHelper.php b/core/lib/Drupal/Component/Plugin/PluginHelper.php index fc4360fa95ec49084935a8b4321a610ac2a945cb..550a0913430faf6c2ba3e97136a708b97bdd5e57 100644 --- a/core/lib/Drupal/Component/Plugin/PluginHelper.php +++ b/core/lib/Drupal/Component/Plugin/PluginHelper.php @@ -2,10 +2,15 @@ namespace Drupal\Component\Plugin; +@trigger_error('The ' . __NAMESPACE__ . '\PluginHelper is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Instead, use instanceof() to check for \Drupal\Component\Plugin\ConfigurableInterface. See http://drupal.org/node/3198285', E_USER_DEPRECATED); + /** * A helper class to determine if a plugin is configurable. * - * @todo Deprecate this class. https://www.drupal.org/node/3105685 + * @deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Instead, use + * instanceof() to check for \Drupal\Component\Plugin\ConfigurableInterface. + * + * @see https://www.drupal.org/node/3198285 */ class PluginHelper { diff --git a/core/lib/Drupal/Core/Plugin/DefaultLazyPluginCollection.php b/core/lib/Drupal/Core/Plugin/DefaultLazyPluginCollection.php index c3fa2ee5bb2ca71fc7c6f40d1b0800ea35ded4ed..ee0f90d4f77d9b61631a8536abd2d80b4b4d23ca 100644 --- a/core/lib/Drupal/Core/Plugin/DefaultLazyPluginCollection.php +++ b/core/lib/Drupal/Core/Plugin/DefaultLazyPluginCollection.php @@ -2,9 +2,9 @@ namespace Drupal\Core\Plugin; +use Drupal\Component\Plugin\ConfigurableInterface; use Drupal\Component\Plugin\Exception\PluginNotFoundException; use Drupal\Component\Plugin\LazyPluginCollection; -use Drupal\Component\Plugin\PluginHelper; use Drupal\Component\Plugin\PluginManagerInterface; use Drupal\Core\DependencyInjection\DependencySerializationTrait; @@ -112,7 +112,7 @@ public function getConfiguration() { $this->instanceIds = $this->originalOrder + $current_order; foreach ($this as $instance_id => $instance) { - if (PluginHelper::isConfigurable($instance)) { + if ($instance instanceof ConfigurableInterface) { $instances[$instance_id] = $instance->getConfiguration(); } else { @@ -158,7 +158,7 @@ public function setConfiguration($configuration) { public function setInstanceConfiguration($instance_id, array $configuration) { $this->configurations[$instance_id] = $configuration; $instance = $this->get($instance_id); - if (PluginHelper::isConfigurable($instance)) { + if ($instance instanceof ConfigurableInterface) { $instance->setConfiguration($configuration); } } diff --git a/core/lib/Drupal/Core/Plugin/DefaultSingleLazyPluginCollection.php b/core/lib/Drupal/Core/Plugin/DefaultSingleLazyPluginCollection.php index df1cc78d7978d2a3e5a4390c8f6c391873b6c477..334fac340a42f2c738c2757ac7875874a06d35d5 100644 --- a/core/lib/Drupal/Core/Plugin/DefaultSingleLazyPluginCollection.php +++ b/core/lib/Drupal/Core/Plugin/DefaultSingleLazyPluginCollection.php @@ -2,7 +2,7 @@ namespace Drupal\Core\Plugin; -use Drupal\Component\Plugin\PluginHelper; +use Drupal\Component\Plugin\ConfigurableInterface; use Drupal\Component\Plugin\PluginManagerInterface; use Drupal\Component\Plugin\LazyPluginCollection; use Drupal\Core\DependencyInjection\DependencySerializationTrait; @@ -67,7 +67,7 @@ protected function initializePlugin($instance_id) { */ public function getConfiguration() { $plugin = $this->get($this->instanceId); - if (PluginHelper::isConfigurable($plugin)) { + if ($plugin instanceof ConfigurableInterface) { return $plugin->getConfiguration(); } else { @@ -81,7 +81,7 @@ public function getConfiguration() { public function setConfiguration($configuration) { $this->configuration = $configuration; $plugin = $this->get($this->instanceId); - if (PluginHelper::isConfigurable($plugin)) { + if ($plugin instanceof ConfigurableInterface) { $plugin->setConfiguration($configuration); } return $this; diff --git a/core/modules/system/src/Entity/Action.php b/core/modules/system/src/Entity/Action.php index 26c9c39bd3db838de3717fddccc97af71ececed9..a7590ff292b2a0def78857b3d7e3385e81bfcade 100644 --- a/core/modules/system/src/Entity/Action.php +++ b/core/modules/system/src/Entity/Action.php @@ -2,7 +2,7 @@ namespace Drupal\system\Entity; -use Drupal\Component\Plugin\PluginHelper; +use Drupal\Component\Plugin\ConfigurableInterface; use Drupal\Core\Config\Entity\ConfigEntityBase; use Drupal\Core\Config\Entity\ConfigEntityInterface; use Drupal\Core\Entity\EntityWithPluginCollectionInterface; @@ -133,7 +133,7 @@ public function execute(array $entities) { * {@inheritdoc} */ public function isConfigurable() { - return PluginHelper::isConfigurable($this->getPlugin()); + return $this->getPlugin() instanceof ConfigurableInterface; } /** diff --git a/core/tests/Drupal/Tests/Component/Plugin/PluginHelperLegacyTest.php b/core/tests/Drupal/Tests/Component/Plugin/PluginHelperLegacyTest.php new file mode 100644 index 0000000000000000000000000000000000000000..bed7ab2d96065dd270711f24e89efc0c2b350e4d --- /dev/null +++ b/core/tests/Drupal/Tests/Component/Plugin/PluginHelperLegacyTest.php @@ -0,0 +1,25 @@ +<?php + +namespace Drupal\Tests\Component\Plugin; + +use Drupal\Component\Plugin\ConfigurableInterface; +use Drupal\Component\Plugin\PluginHelper; +use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; + +/** + * @coversDefaultClass \Drupal\Component\Plugin\PluginHelper + * @group Plugin + * @group legacy + */ +class PluginHelperLegacyTest extends TestCase { + use ExpectDeprecationTrait; + + public function testPluginHelperDeprecation(): void { + $this->expectDeprecation('The Drupal\Component\Plugin\PluginHelper is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Instead, use instanceof() to check for \Drupal\Component\Plugin\ConfigurableInterface. See http://drupal.org/node/3198285'); + $this->assertEquals($this instanceof ConfigurableInterface, PluginHelper::isConfigurable($this)); + $plugin = $this->createMock(ConfigurableInterface::class); + $this->assertEquals($plugin instanceof ConfigurableInterface, PluginHelper::isConfigurable($plugin)); + } + +}