Problem/Motivation

Following #3398534: Allow form service wiring via constructor parameter attributes forms now support autowiring. We should be able to remove custom create() methods from most if not all forms.

Steps to reproduce

Proposed resolution

Update form classes across Drupal core to:

  • Remove custom create() methods where dependencies can be resolved via autowiring
  • Refactor constructors to use constructor property promotion
  • Remove redundant constructor PHPDoc

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3578361

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

longwave created an issue. See original summary.

sourav_paul’s picture

Working on it..

longwave’s picture

Status: Active » Needs work

Thanks - in most cases we shouldn't need the attribute at all, because the service can be inferred from the object/interface type that is required. Also, coding standards checks are failing.

sourav_paul’s picture

Thanks @longwave for the clarity. I've implemented those changes as per suggestion. kindly let me know if there is anything need to change.

sourav_paul’s picture

Status: Needs work » Needs review
longwave’s picture

Status: Needs review » Needs work

Some test failures to sort out.

Also we need to decide for which forms we want to provide BC in the constructor, where before e.g. we passed an entity storage handler and now we pass the entity type manager instead. I imagine most downstream changes are via form alter hooks instead of actually extending? Not sure.

sourav_paul’s picture

Status: Needs work » Needs review

Thanks for the feedback. I investigated the failing jobs and identified the root cause: removing all #[Autowire] attributes broke autowiring for ConfigurableLanguageManagerInterface in language forms.

CI failure source was: AutowiringFailedException for NegotiationConfigureForm::__construct(), which then caused the widespread “Save settings/Add language button not found” failures.

I restored explicit #[Autowire(service: 'language_manager')] only for the forms that require it (LanguageFormBase, NegotiationBrowserForm, NegotiationConfigureForm).

On constructor BC: the storage→entity type manager signature changes are in @internal forms (NodeRevisionDeleteForm, NodeRevisionRevertForm, NodeRevisionRevertTranslationForm, NegotiationConfigureForm). I’ve left them as-is for now, but I can add BC constructor handling if we want extra compatibility even for internal classes.

sivaji_ganesh_jojodae made their first commit to this issue’s fork.

sourav_paul’s picture

@sivaji_ganesh_jojodae Thanks for rebasing the branch, But this is not a correct way to work on any issue while someone is already working on it (atleast you should wait 3days).

longwave’s picture

Status: Needs review » Needs work

Let's minimise the changes required here where we can - there is no need to reformat most of the constructors.

sourav_paul’s picture

Status: Needs work » Needs review

Thanks @Dave for your guidance, I've removed all constructor white space formatting.

Feel free to know, if there anything you need to fix.

smustgrave’s picture

Status: Needs review » Needs work

Not to expand scope too much but think since we are touching these files we should do constructor promotion while we are at. If not lets least drop the docs since that's not the default anymore.

sivaji_ganesh_jojodae’s picture

Assigned: Unassigned » sivaji_ganesh_jojodae

I am working on the constructor property promotion.

sivaji_ganesh_jojodae’s picture

Status: Needs work » Needs review

I think necessary changes for constructor property promotion are committed.

sivaji_ganesh_jojodae’s picture

Assigned: sivaji_ganesh_jojodae » Unassigned
smustgrave’s picture

Status: Needs review » Needs work

Thanks other part of my comment was also dropping the docs on the construct now

sivaji_ganesh_jojodae’s picture

Issue summary: View changes
Status: Needs work » Needs review

Removed the constructor PHPDoc blocks. Also updated the issue summary to include the scope expansions mentioned in the comments.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

Looks much cleaner now, no further feedback from me.

longwave’s picture

Opened #3586556: Add a service alias for ConfigurableLanguageManagerInterface as a followup which would clean up the three instances of #[Autowire(service: 'language_manager')].

longwave’s picture

Status: Reviewed & tested by the community » Needs work

Added some comments.

Not sure any of the config forms should use property promotion for the typed config manager, as they pass it to the parent, ie.

    protected TypedConfigManagerInterface $typedConfigManager,

should maybe be

    TypedConfigManagerInterface $typedConfigManager,

Opened #3586565: Consider using #[Required] to inject dependencies into ConfigFormBase to investigate if we can remove this entirely.

sivaji_ganesh_jojodae’s picture

Status: Needs work » Needs review

@longwave, thanks for catching the TypedConfigManagerInterface property -- that’s been fixed in my latest update. I’ve applied a similar fix to the properties in NodeRevisionRevertTranslationForm.php as well.

There are a few other open comments; could you clarify what changes are expected there?

dcam’s picture

Status: Needs review » Needs work

I added a few comments to the MR, including two items that need to be addressed.

If I counted correctly there are currently four classes that break backward compatibility. Forms are considered internal, but committers may require that backward compatibility be added to them anyway. That said, I'm willing to RTBC the MR and send it up for committer review if the other issues that I flagged are addressed.