Problem/Motivation
Follow up #2729597: [meta] Replace \Drupal with injected services where appropriate in core and see it for more details. And take this fixed issue and its commit as an example.
Proposed resolution
Inject redirect.destination service instead of using \Drupal:: destination() in non-tests where possible
See CR https://www.drupal.org/node/3343983
Command to get the target classes to work with:
$ grep -nR '\\Drupal::destination()' . | grep -v Test | grep -v "\.module" | grep -v '\.inc' | grep -v 'Trait\.php' | grep -v 'api.php' | grep -v SystemCompactLink | grep -v RedirectDestinationInterface | grep -v UserLoginBlock
Note: Usages in SystemCompactLink and UserLoginBlock are inside static methods. And usage in RedirectDestinationInterface is in the comment.
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #31 | interdiff_29-31.txt | 2.34 KB | mrinalini9 |
| #31 | 3123214-31.patch | 11.79 KB | mrinalini9 |
| #29 | 3123214-29.patch | 10.38 KB | ranjith_kumar_k_u |
| #23 | 3123214-23.patch | 10.4 KB | suresh prabhu parkala |
| #20 | 3123214-20.patch | 11.74 KB | nitesh624 |
Issue fork drupal-3123214
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
Comment #3
nitesh624Comment #4
nitesh624Comment #5
nitesh624Comment #6
nitesh624Comment #7
jungleThanks for working on this.
It's not just replacing
\Drupal::destination()with\Drupal::service('redirect.destination')It's to replace
\Drupal::destination()and\Drupal::service('redirect.destination')with IoC injection where possiblePlease see the parent issue and closed/fixed sibling issues for reference and for more.
Comment #8
nitesh624Comment #9
nitesh624Changes done as per #7
Comment #10
nitesh624Comment #11
nitesh624Comment #12
nitesh624Comment #13
nitesh624Comment #14
nitesh624Comment #15
nitesh624Comment #16
nitesh624Comment #17
nitesh624Comment #18
nitesh624Comment #19
nitesh624Comment #20
nitesh624Reuploading patch from #15 as IOC injection is resulting error
Comment #21
nitesh624Comment #22
junglePer the parent issue, rescoping this to do it for non-test code.
So i have to set this back to NW, sorry!
Comment #23
suresh prabhu parkala commentedPatch did not applied so re-rolled and also removed changes from tests. Please review.
Comment #29
ranjith_kumar_k_u commentedRerolled #23
Comment #30
smustgrave commentedSeems there still two instances of
\Drupal::destination()->getAsArray
That should be replaced.
Comment #31
mrinalini9 commentedUpdated patch #29 by addressing #30, please review it.
Thanks!
Comment #32
smustgrave commentedSeems all instances have been replaced.
Comment #33
jungleAll changes should be reverted and are invalid. Replacing
\Drupal::destination()with\Drupal::service('redirect.destination')does not in scope here and makes no sense. They are almost the same. And it's not using IoC injection.An example coming in the next comment.
Comment #34
jungleTaking core/modules/views/src/Plugin/views/field/Links.php as an example.
Note:
1. I might pick the wrong class, as the example. It's an abstract class, not a normal one. Not sure if abstract classes should be handled specially. Please just treat it as a normal class.
2. A change record is required, and please update the placeholder CHANGE-RECORD-NODE-ID with its node ID.
3. IoC is class specific, do not touch .module files etc.
Comment #35
jungleSee parent issue for more details.
Comment #36
jungleContinue with #34
4. Constructor property promotion is used. see https://stitcher.io/blog/constructor-promotion-in-php-8
Comment #38
jungleSwitching to MR and re-wording the title without the term IoC which some contributors might be unfamiliar with. And updating the issue summary to add a fixed issue and its commit as an example.
Comment #39
jungleComment #40
jungleComment #41
jungleAdd Command to get classes to work with to IS
Comment #42
jungleThe command is used to find the target classes.
Note: Usages in SystemCompactLink and UserLoginBlock are inside static methods. And usage in RedirectDestinationInterface is in the comment.
Comment #43
jungleCR updated
Comment #44
smustgrave commentedThanks @jungle!
Comment #45
alexpottCommitted 9ed7086 and pushed to 10.1.x. Thanks!
Comment #48
amateescu commentedFWIW, the changes to the workspace forms from this issue were not correct, see #3376293-12: WorkspacePublishForm $redirectDestination parameter appears not to be used.
Comment #49
quietone commentedPublished the CR.