Leveraging on Symfony's DebugClassLoader, it's now possible to add arguments to methods in interfaces in next major release.
Since it's normally a BC break to introduce new arguments (because any implementing class that does not comply with the changed signature would fail at loading), this is a two steps process.
Step 1 - prepare the new signature
During the current release cycle, introduce the new argument(s) in an inline comment, for example:
- public function submitForm($form_arg, FormStateInterface &$form_state);
+ public function submitForm($form_arg, FormStateInterface &$form_state /* , mixed ...$args */);
Document the new argument(s) in the docblock of the method, inside an PHPCS ignore block to prevent PHPCS to fire an error when parsing the signature of the method; in the comments include a @see to a follow-up issue that will take care of actually doing the change in the next major release:
* phpcs:disable Drupal.Commenting
* @todo Uncomment new method parameters before drupal:11.0.0.
* @see https://www.drupal.org/project/drupal/issues/3354672
*
* @param mixed ...$args
* Any additional arguments are passed on to the functions called by
* \Drupal::formBuilder()->getForm(), including the unique form constructor
* function. For example, the node_edit form requires that a node object is
* passed in here when it is called. These are available to implementations
* of hook_form_alter() and hook_form_FORM_ID_alter() as the array
* $form_state->getBuildInfo()['args'].
* phpcs:enable
Tag the follow-up issue with 'Major version only'.
This will let the testing framework trigger deprecation errors for the implementing classes that do not have, yet, the to-be signature in place. In order to prevent tests fail because of that, add an ignore line in .deprecation-ignore.txt, like e.g.
# Drupal 11.
%FormBuilder::getForm\(\).* will require a new "mixed \.\.\. \$args" argument in the next major version of its interface%
%FormBuilder::submitForm\(\).* will require a new "mixed \.\.\. \$args" argument in the next major version of its interface%
Step 2 - implement the new signature
Once the branch opens for issues for new major release issues,
a) remove the inline comment from the interface, exposing the new full signature:
- public function submitForm($form_arg, FormStateInterface &$form_state /* , mixed ...$args */);
+ public function submitForm($form_arg, FormStateInterface &$form_state, mixed ...$args);
b) remove the PHPCS ignore and @todo from the docblock
c) implement the new signature in the concrete classes
d) remove the ignore line from the .deprecation-ignore.txt file.