Provide a helper trait for removing deprecated constructor params

Created on 22 August 2023, over 1 year ago
Updated 24 August 2023, over 1 year ago

Problem/Motivation

Coming from #3278431-53: Use PHP 8 constructor property promotion .

When we deprecate a constructor param we need to provide union types for all params to the right of (and including) the param that is deprecated, then reassign when the deprecated param has been passed.

This looks something like this:

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;
}

Steps to reproduce

See \Drupal\block\Plugin\migrate\process\BlockTheme::__construct.

Proposed resolution

It would be nice if we had a trait that did a lot of this consistently and automatically.

public function __construct(array $configuration, $plugin_id, $plugin_definition, Config|MigrationInterface $theme_config, array|Config $themes) {
  parent::__construct($configuration, $plugin_id, $plugin_definition);
  $this->removeDeprecatedParam(
    args: func_get_args(),
    position: 3,
    deprecatedClassName: MigrationInterface::class,
    message: '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',
  );
}

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

📌 Task
Status

Active

Version

11.0 🔥

Component
Base 

Last updated 1 day ago

Created by

🇦🇺Australia mstrelan

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024