From 2bcbc265043debd73ad623b1e03e189eeda21e16 Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Sat, 23 Jul 2022 08:55:46 +0100
Subject: [PATCH] Issue #3105685 by andypost, mrinalini9: Deprecate
 PluginHelper::isConfigurable()

---
 .../Drupal/Component/Plugin/PluginHelper.php  |  7 +++++-
 .../Plugin/DefaultLazyPluginCollection.php    |  6 ++---
 .../DefaultSingleLazyPluginCollection.php     |  6 ++---
 core/modules/system/src/Entity/Action.php     |  4 +--
 .../Plugin/PluginHelperLegacyTest.php         | 25 +++++++++++++++++++
 5 files changed, 39 insertions(+), 9 deletions(-)
 create mode 100644 core/tests/Drupal/Tests/Component/Plugin/PluginHelperLegacyTest.php

diff --git a/core/lib/Drupal/Component/Plugin/PluginHelper.php b/core/lib/Drupal/Component/Plugin/PluginHelper.php
index fc4360fa95ec..550a0913430f 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 c3fa2ee5bb2c..ee0f90d4f77d 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 df1cc78d7978..334fac340a42 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 26c9c39bd3db..a7590ff292b2 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 000000000000..bed7ab2d9606
--- /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));
+  }
+
+}
-- 
GitLab