Verified Commit 2bcbc265 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3105685 by andypost, mrinalini9: Deprecate PluginHelper::isConfigurable()

parent 50ddf37f
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -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 {

+3 −3
Original line number Diff line number Diff line
@@ -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);
    }
  }
+3 −3
Original line number Diff line number Diff line
@@ -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;
+2 −2
Original line number Diff line number Diff line
@@ -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;
  }

  /**
+25 −0
Original line number Diff line number Diff line
<?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));
  }

}