Problem/Motivation
Follow up #2729597: [meta] Replace \Drupal with injected services where appropriate in core
Some classes does not inject form builder service via DI
Proposed resolution
Replace all of them with IoC injection where possible
Specifically UserLoginBlock and ActionListBuilder
Following should stay as is for BC
core/lib/Drupal/Core/Config/Entity/DraggableListBuilder.php:25: $this->formBuilder = \Drupal::formBuilder();
core/modules/views/src/Plugin/views/display/DisplayPluginBase.php:2263: $form = \Drupal::formBuilder()->getForm($form_object, $view, $output);
core/modules/views/src/Plugin/views/exposed_form/ExposedFormPluginBase.php:134: $form = \Drupal::formBuilder()->buildForm('\Drupal\views\Form\ViewsExposedForm', $form_state);
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Comments
Comment #3
nitesh624Comment #4
nitesh624@jungle In core i have seen that many place \Drupal::formBuilder() has been used in comments. so do we consider changing there also.
Comment #5
nitesh624Comment #6
nitesh624Comment #7
nitesh624Replace occurance of \Drupal::formBuilder() with IoC injection in comments also
Comment #8
nitesh624Removing the unnecessary changes from #7
Comment #9
nitesh624Comment #10
jungleThanks for working on this.
It's not just replacing
\Drupal::formBuilder()with\Drupal::service('form_builder')It's to replace \Drupal::formBuilder() and \Drupal::service('form_builder') with IoC injection where possible
Please see the parent issue and closed/fixed sibling issues for reference and for more.
Comment #11
nitesh624Comment #12
nitesh624Comment #13
nitesh624Comment #14
hardik_patel_12 commented@nitesh624 , thankyou for working on this. Kindly see comment mentioned at #10 It's to replace \Drupal::formBuilder() and \Drupal::service('form_builder') with IoC injection where possible.
Kindly review a new patch.
Comment #15
msutharsComment #16
msuthars@Hardik_Patel_12 I reviewed the patch and found some changes:
1. You forgot to use that injected service in UserLoginBlock, you only inject the service not replace it with \Drupal::formBuilder().
2. ActionListBuilder is pending for Ioc service injection.
Comment #17
suresh prabhu parkala commentedPlease review!
Comment #18
hardik_patel_12 commentedAdding Change Record and deprecation error for UserLoginBlock file. Kindly review a new patch.
Checking remaining replacement files.
All calls are commented except below one.
Not sure why it was done this way and can we replace this with injected service or not.
@msuthars, for ActionListBuilder i am not sure about this we can inject service in it or not.
Comment #19
junglePer the parent issue, rescoping this to do it for non-test code.
Reviewing
Comment #20
jungleCR link should be changed to https://www.drupal.org/node/3159776
__CLASS__, for example:'Calling ' . __CLASS__ . '::' . __METHOD__ . '() without the ...grep -v '//' | grep -v '*'-- ignore occurrences in comments. For the one in\Drupal\Core\Config\Entity\DraggableListBuilder::formBuilder()I think it can be ignored.
Comment #21
hardik_patel_12 commentedKindly review a new patch , it is covering points as suggested at #20 and changed the use statements to be alphabetical.
Comment #27
smustgrave commentedThis issue is being reviewed by the kind folks in Slack, #need-reveiw-queue. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge require as a guide.
Unfortunately this missed the D10 boat so this will have to be updated for deprecated in 10.1.x and required in 11.
Comment #28
_utsavsharma commentedAddressed the point in #27.
Please review.
Comment #29
_utsavsharma commentedUpdated for deprecated in 10.1.x and required in 11 to 10.1.0 and 11.0.0.
Please review.
Comment #30
smustgrave commentedThank you for updating that
After applying the patch and doing a search for \Drupal::formBuilder() in my phpstorm. Everything I found was in a module, inc, comment, test.
Only one I have a question on is ActionListBuilder but will let the committer decide if that needs to be replaced.
Comment #31
catchHad a look at ActionListBuilder and to me that looks in scope - class already has a constructor and ::createInstance() method, so let's do that one here. Patch looks fine for the instance it changes.
Comment #33
joachim commentedDraggableListBuilder should also be replaced.
Comment #35
andypostit has changes as trait extracted already via #2989889: Extract DraggableListBuilderTrait from DraggableListBuilder for use with content entities
btw Action module is going to be deprecated, see #3343369: [meta] Tasks to deprecate Actions UI module
Comment #36
andypostRebased and updated deprecation for 10.3
The
\Drupal\Core\Config\Entity\DraggableListBuilder::__construct()has following comment so should stay as isAlso updated IS
Comment #37
smustgrave commentedCan the CR be updated please.
Comment #38
andypostupdated https://www.drupal.org/node/3159776
Comment #39
joachim commentedDoes this need a CR? Entity handlers and plugin classes are internal.
Comment #40
smustgrave commentedCR reads well.
Comment #43
catchIMO we should not add CRs for internal code, especially not constructor changes, and just link to the issue itself - however the extra work's already been done here and the docs for when to add a CR aren't conclusive either way, so committed/pushed to 11.x and cherry-picked to 10.3.x, thanks!
Comment #44
quietone commentedThe change record here should include a before and after example to help the reader. And I think it needs rewording to be easier to read.
Comment #45
andypostRe #43 sometimes we add like https://www.drupal.org/node/3395991
@quietone I think CR can add, that classes extending this ones should be updated to pass
form_builderservice to parentComment #47
quietone commented