- Issue created by @mondrake
- š¬š§United Kingdom catch
If we can do š Remove the debug classloader deprecation silencing for Drupal interfaces Closed: duplicate then I think the next step would be to add docs to https://www.drupal.org/about/core/policies/core-change-policies/bc-policy ā on how to use it to add parameters to interface methods.
For adding/changing type hints we could probably do something like removing a parameter then adding it back again, but should be separate issues probably.
- š®š¹Italy mondrake š®š¹
Add to IS a list of cases to cover. Anything else?
- š®š¹Italy mondrake š®š¹
- š¬š§United Kingdom catch
adding a method to the interface
removing a method from the interfaceThese are already covered in the existing bc policy, IMO we should not bundle things into one issue but handle one at a time where there are deficiencies.
- š¬š§United Kingdom catch
removing parameter(s) from existing method
this is also already covered by the existing bc policy.
- š¬š§United Kingdom catch
š Prepare FormBuilder for variadic functions Fixed did exactly what we need to document here, so I think the next step is adding that as an example to the bc policy at https://www.drupal.org/about/core/policies/core-change-policies/drupal-d... ā
- š³š±Netherlands bbrala Netherlands
Ok, to get this rolling i attacked a proposed addition to the core page on deprecations.
- Status changed to Needs review
over 1 year ago 8:21am 24 August 2023 - last update
over 1 year ago Patch Failed to Apply - š³š±Netherlands bbrala Netherlands
ANd readable text:
ā
Adding arguments to interface methods
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 š [11.x] Adjust parameters in interfaces Active
*
* @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:enableTag 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: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);remove the PHPCS ignore and @todo from the docblock,
implement the new signature in the concrete classes
remove the ignore line from the .deprecation-ignore.txt file.
ā - š³š±Netherlands bbrala Netherlands
Updated covered bullet points as pointed out by catch
- Status changed to Needs work
over 1 year ago 8:47am 24 August 2023 The Needs Review Queue Bot ā tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide ā to find step-by-step guides for working with issues.
- š³š±Netherlands bbrala Netherlands
Suggestion by @catch is to use something like:
- public function foo(OldInterface $bar) + public function foo(/** OldInterface|NewInterface $bar */)
For changing interface typehints. Was trying to write this, but need to check it with some real code. Also not sure if if this would need to be an example as above of perhaps:
- public function foo(array $bar) + public function foo(/** NewInterface $bar */)
That perhaps feels a little more realistic in context of Drupal code.
- Status changed to Needs review
over 1 year ago 8:51am 24 August 2023 - š³š±Netherlands bbrala Netherlands
Ok, lets see, this seems like an good idea (tm). Added example for changing method signature:
Or change the typehint of an argument, for example:
- public function foo(string $bar); + public function foo(/* string|Stringable $bar */);
Document the changes 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%
Once the branch opens for issues for new major release issues:
- 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);
or
- public function foo(/* string|Stringable $bar */); + public function foo(string|Stringable $bar);
- remove the PHPCS ignore and
@todo
from the docblock, - implement the new signature in the concrete classes
- remove the ignore line from the
.deprecation-ignore.txt
file.
- š³š±Netherlands bbrala Netherlands
Update propopsed solution to only used fake classes/interfaces/methods/arguments
- Status changed to RTBC
over 1 year ago 10:16am 24 August 2023 - š¬š§United Kingdom catch
Talked with @bbrala about this in slack, I think the proposed wording is really clear, and covers as many cases as we could think of, so ready to go for me.
RTBC and tagging for documentation updates.
- š³š±Netherlands bbrala Netherlands
Documentation has been updated ā .
- š¬š§United Kingdom catch
Docs changes look good but I wonder if we should move it directly under https://www.drupal.org/about/core/policies/core-change-policies/drupal-d... ā since it's dealing with parameters?
- š³š±Netherlands bbrala Netherlands
Hmm, both could be right, the placement right now is classes -> interfaces.
I don't mind either way, both make sense in my mind.
- š¬š§United Kingdom joachim
> %FormBuilder::getForm\(\).* will require a new "mixed \.\.\. \$args" argument in the next major version of its interface%
Is the idea that implementations/subclasses can add the parameters as optional right away, then then they're compatible with both D10 (without the param) and D11 (with the param)?
I'm assuming this message isn't under our control -- but it would be nice if it said that or if we documented that somewhere.
- š³š±Netherlands bbrala Netherlands
Think you might wanna look at the is, that's close to what was actually posted. Does the doc page still show that form example? Thought I generalised it.
- š¬š§United Kingdom joachim
AFAICT, the IS doesn't explain how implementors should react to the deprecation.
And the IS says how to ignore the deprecation warning in a test, but it doesn't say where the warning is generated.
- š¬š§United Kingdom catch
The warning is generated by Symfony's debug classloader (and this is why we have no control over the contents).
Implementors should add the extra parameter or type hint to their current codebase - PHP won't complain and it'll be forwards compatible for when the interface changes in the next major release.
- last update
over 1 year ago Patch Failed to Apply - last update
over 1 year ago Patch Failed to Apply - last update
over 1 year ago Patch Failed to Apply - last update
over 1 year ago Patch Failed to Apply - last update
over 1 year ago Patch Failed to Apply - last update
over 1 year ago Patch Failed to Apply - last update
over 1 year ago Patch Failed to Apply - last update
over 1 year ago Patch Failed to Apply - last update
over 1 year ago Patch Failed to Apply - last update
over 1 year ago Patch Failed to Apply - Status changed to Fixed
over 1 year ago 4:43am 15 September 2023 - š³šæNew Zealand quietone
I think that #27 and #28, about the placement of the new section on the page, has been resolved. xjm moved it to it's own heading, added the links to the tag and other tidying up. Adding credit for xjm for that work.
The new addition is at Interface method signature changes ā .
Thanks everyone!
Automatically closed - issue fixed for 2 weeks with no activity.