Verified Commit f979f42e authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3323209 by Spokje, mondrake, smustgrave, alexpott, xjm: Deprecate...

Issue #3323209 by Spokje, mondrake, smustgrave, alexpott, xjm: Deprecate calling Drupal\block\Plugin\migrate\process\BlockTheme::_construct() with the $migration argument
parent 3fc94dc6
Loading
Loading
Loading
Loading
+15 −20
Original line number Diff line number Diff line
@@ -2,11 +2,11 @@

namespace Drupal\block\Plugin\migrate\process;

use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\Core\Config\Config;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
use Drupal\Core\Config\Config;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

@@ -17,22 +17,15 @@
 */
class BlockTheme extends ProcessPluginBase implements ContainerFactoryPluginInterface {

  /**
   * Contains the configuration object factory.
   *
   * @var \Drupal\Core\Config\ConfigFactoryInterface
   */
  protected $configFactory;

  /**
   * Contains the system.theme configuration object.
   *
   * @var \Drupal\Core\Config\Config
   */
  protected $themeConfig;
  protected Config $themeConfig;

  /**
   * List of themes available on the destination.
   *
   * @var string[]
   */
  protected array $themes;

@@ -45,15 +38,18 @@ class BlockTheme extends ProcessPluginBase implements ContainerFactoryPluginInte
   *   The plugin ID for the plugin instance.
   * @param mixed $plugin_definition
   *   The plugin implementation definition.
   * @param \Drupal\migrate\Plugin\MigrationInterface $migration
   *   The migration entity.
   * @param \Drupal\Core\Config\Config $theme_config
   * @param \Drupal\Core\Config\Config|\Drupal\migrate\Plugin\MigrationInterface $theme_config
   *   The system.theme configuration factory object.
   * @param array $themes
   * @param string[]|\Drupal\Core\Config\Config $themes
   *   The list of themes available on the destination.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, Config $theme_config, array $themes) {
    parent::__construct($configuration, $plugin_id, $plugin_definition, $migration);
  public function __construct(array $configuration, $plugin_id, $plugin_definition, Config|MigrationInterface $theme_config, array|Config $themes) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    if ($theme_config instanceof MigrationInterface) {
      @trigger_error('Calling ' . __CLASS__ . '::__construct() with the $migration argument is deprecated in drupal:10.1.0 and is removed in drupal:11.0.0. See https://www.drupal.org/node/3323212', E_USER_DEPRECATED);
      $theme_config = func_get_arg(4);
      $themes = func_get_arg(5);
    }
    $this->themeConfig = $theme_config;
    $this->themes = $themes;
  }
@@ -61,12 +57,11 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition
  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static(
      $configuration,
      $plugin_id,
      $plugin_definition,
      $migration,
      $container->get('config.factory')->get('system.theme'),
      $container->get('theme_handler')->listInfo()
    );
+34 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\Tests\block\Unit\Plugin\migrate\process;

use Drupal\block\Plugin\migrate\process\BlockTheme;
use Drupal\Core\Config\Config;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\Tests\UnitTestCase;

/**
 * Tests the deprecation notices of the block theme.
 *
 * @group legacy
 */
class BlockThemeDeprecationTest extends UnitTestCase {

  /**
   * Tests the deprecation in the constructor.
   */
  public function testConstructorDeprecation(): void {
    $this->expectDeprecation('Calling Drupal\block\Plugin\migrate\process\BlockTheme::__construct() with the $migration argument is deprecated in drupal:10.1.0 and is removed in drupal:11.0.0. See https://www.drupal.org/node/3323212');
    $migration = $this->prophesize(MigrationInterface::class);
    $config = $this->prophesize(Config::class);
    new BlockTheme(
      [],
      '',
      [],
      $migration->reveal(),
      $config->reveal(),
      []
    );
  }

}
+0 −5
Original line number Diff line number Diff line
@@ -825,11 +825,6 @@ parameters:
			count: 1
			path: modules/block/src/BlockListBuilder.php

		-
			message: "#^Method Drupal\\\\Component\\\\Plugin\\\\PluginBase\\:\\:__construct\\(\\) invoked with 4 parameters, 3 required\\.$#"
			count: 1
			path: modules/block/src/Plugin/migrate/process/BlockTheme.php

		-
			message: "#^Variable \\$position might not be defined\\.$#"
			count: 4