Problem/Motivation
In Drupal 10.1, we are changing paths and menu navigation for several pages in the Block and Block content modules. In particular,
- #2987964: Move custom block types admin link to admin/structure changes
/admin/structure/block/block-content/typesto/admin/structure/block-content - #2317981: Move block content edit and delete routes under admin/content/block to improve IA for editors and fix breadcrumbs changes
/block/{block_content}to/admin/content/block-content/{block_content}.
When we change paths, we provide redirects from the old ones to the new ones. See #3333383: Create a redirect for the new Block types path. That issue and #2317981 create redirects for the primary paths and also for child paths defined in the block_content module.
This issue is about creating redirect for the child paths provided by other modules, such as content_translation, config_translation, and user. We also want to make it easy for contributed modules to do the same.
Steps to reproduce
- Install Drupal 10.1.x with the Standard or Umami profile.
- Visit the path
/admin/structure/block/block-content/types/manage/basic/permissions - Admire your site's 404 page.
The expected behavior is to be redirected to the new path, /admin/structure/block-content/manage/basic/permissions, with warning messages in the messages area and in the logs.
Proposed resolution
- Add the helper class
Drupal\Core\Routing\PathChangedHelperso that controller classes can create BC redirects conveniently and in a standard way. - Update existing redirects to use the new helper class.
- Add a BC route for
entity.block_content_type.edit_form, since that is the Field UI base path. - Use a new route subscriber to add routes to redirect from old child paths to new ones.
Remaining tasks
User interface changes
Redirect to the new path with a warning message instead of giving a 404 (page not found) response.
API changes
Does adding a new helper class count as an API change? Or a new route subscriber?
Data model changes
None
| Comment | File | Size | Author |
|---|---|---|---|
| #23 | 3351750-nr-bot.txt | 90 bytes | needs-review-queue-bot |
| #15 | 3351750-nr-bot.txt | 3.2 KB | needs-review-queue-bot |
Issue fork drupal-3351750
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:
- 3351750-create-bc-redirects
changes, plain diff MR !3801
Comments
Comment #2
benjifisherI am adding one item to the proposed resolution: update existing redirects to use the new trait.
I considered postponing this issue on #3318112: [PP1] Move "Block layout" from Structure to Appearance, but it would not be hard to copy the helper function from the MR on that issue, so I think the two issues can be done in either order.
Comment #3
benjifisherI am adding the issues mentioned in the issue summary as related issues.
Comment #4
benjifisherHow should we handle the
destinationquery parameter?I do not think that (2) is viable. For example, the Configure link (before #3318112: [PP1] Move "Block layout" from Structure to Appearance, using the Umami profile) is
/en/admin/structure/block/manage/claro_page_title?destination=/en/admin/structure/block/list/claro. The "old path" is/admin/structure/block/manage/{plugin_id}and we need to update "structure" to "appearance".If we use (2), then we have to hope that we created a redirect for the destination, if it is also updated. Assuming we did, then there will be another warning in the admin UI.
I vote for (3).
Comment #5
larowlanYeah 3 sounds best
Comment #7
benjifisherI started thinking about the single-responsibility principle, and I realized that the helper function in #3318112: [PP1] Move "Block layout" from Structure to Appearance is an abomination. Instead of a trait, we should have a helper class and use it in a controller like this:
I have a first draft of the helper function in the MR, so I am setting the issue status to NW. I am updating the first part of the Proposed resolution in the issue summary.
Comment #8
benjifisherI think it does not make sense to pass the URL for the change record to the helper function only to have it sent back as one of the parameters. It is also not a great idea for the helper function to decide the placeholder names. So the new version is used like this:
I wonder whether, for consistency, I should replace the
redirect()method with one that just returns the full URL as a string.Comment #9
benjifisherI made the changes suggested on the MR and implemented Step 2 in the proposed resolution.
The new function bodies are the same number of lines as the old ones, only slightly simpler. The doc blocks and parameter lists are more complicated, since they have to declare the route match and request objects. At this point, it is not clear that the helper class (and the extra level of indirection) is worth it. But the existing controllers are as simple as possible: no arguments, no query parameters. In #3318112: [PP1] Move "Block layout" from Structure to Appearance, we have to deal with both, and I think it is worth handling arguments and query parameters (and stripping
destination) in one place.One change is that the new code uses
Url::getInternalPath()instead ofUrl::toString(). That means the warning messages will show paths likeadmin/content/block-content. The old message included at least a leading/; a language prefix like/enon Umami; a directory if Drupal is installed in a subdirectory. Is this a bug or a feature?The issue status is still NW for the last step in the proposed resolution and for tests.
Comment #10
aaronmchaleGrat work on this, thanks Benji!
I wonder if it's worth bringing the log and warning messages into this helper class. My thinking is that it will help us enforce uniformity and reduce code duplication across core. This is effectively a new pattern that we've established for the admin UI and I'd love to (eventually, when I have time) document this in the user interface standards (or somewhere similar).
So thinking like that, to me it makes sense to bring as much of the "boilerplate" code that we can into the helper class to help enforce a uniform pattern across routes that use this.
Maybe even going as far as provide a standard controller class that BC routes can simply point to, rather than each route having to create basically the same controller over and over again.
Comment #11
benjifisher@AaronMcHale:
Have you looked at the helper function in #3318112: [PP1] Move "Block layout" from Structure to Appearance? It does pretty much what you suggest.
I think the individual controller has to be responsible for the messages: deprecation, log, user. We may need a warning or an info or none, depending on which path is being changed and the permissions typically required for that path. I think that sort of variation was discussed on #2862564: Move Custom block library to Content. Managing that variation in the helper function is clunky. As I said in #7 on this issue, I used the single-responsibility principle as a guide.
Once the messages are in the individual controller, I think it makes sense to let that function decide what placeholders to use. But if we want to save a few lines of boilerplate, then we could go back to providing a method
messageParameters()as in Comment #7.Follow-up to my comment in #9: even though it is the same number of lines, the advantage of the current version is that it does not hard-code the route name. That means the same controller can be used by different routes. This will be important when we get to the last step in the proposed resolution.
Comment #12
aaronmchale@benjifisher
On reflection I agree with you that the messages would vary a lot between implementations so it's probably not worth trying to abstract them away, as you said it could get clunky.
I think as long as we eventually have some user interface standards and documentation that can support how this should be implemented, then that should be enough.
Comment #13
benjifisher@AaronMcHale:
I am glad we agree!
I rebased on the current 10.1.x, and added three commits (tiny, small, large).
Adding redirect routes for all the child paths was more work than I expected. I am sure there is room for improvement. It all makes sense to me now, but if it could use some code comments, I am happy to cooperate.
I am setting the status to NR. On the theory that no good deed goes unpunished, I am sure that someone will point out that it needs tests.
I am removing this question from the issue summary:
The routes for the child paths are defined in a new route subscriber for the
block_contentmodule. This is a model that other modules can follow.Comment #14
benjifisherI may not have time to update the MR today, but after sleeping on it, I think there is a much more reliable way to generate the routes that need BC variants. Here is a little test script:
Comment #15
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. 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.
Comment #16
benjifisherI removed the
usestatement flagged in Comment #15 and resolved merge conflicts after #3318549: Rename Custom Block terminology in the admin UI. Back to NR. (But I still plan to make the change I suggested in #14.)Comment #17
smustgrave commentedSeems @larowlan has already done a review and all threads have been addressed.
Do wonder if it deserves it's own change record for how contrib can leverage.
Comment #18
benjifisher@smustgrave:
Thanks for the review, but I think it is premature to call this issue RTBC. There have been changes since @larowlan last commented on the MR, and I just now implemented the idea from #14. (It ends up being a few lines longer, but I still think it is better than hard-coding the list as in the earlier versions.)
I am setting the status back to NR. To be honest, it should probably be NW for tests.
I made one change to the
config_translationmodule. I will add a note to the proposed resolution explaining that.Comment #19
smustgrave commentedSeems the new changes did cause some failures in the tests.
Comment #20
benjifisherThis should fix at least some of the failing tests. It is the
config_translationmodule again.Comment #21
smustgrave commentedProgress! Still some failures but think it's closer.
Comment #22
benjifisherI still blame the
config_translationmodule. Instead of fighting it, I am going back to an explicit list of routes provided by that module and reverting the changes I made to that module.Comment #23
needs-review-queue-bot commentedThe 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.
Comment #24
benjifisherI rebased the MR on the current 10.1.x and resolved the merge conflict. (It was a simple add/add conflict.)
I also added two unit tests and a kernel test for the helper class. The second unit test and the kernel test are redundant, and I would like a second opinion on which one to keep. I think that the unit test is too brittle, so it is worth the extra 510 ms to run the kernel test.
Back to NR.
Comment #25
smustgrave commentedCan't seem to rerun the tests. Can you take a look at that failure?
Comment #26
benjifisherI thought I tested when I made fc02d5d553c268b52cff2586852bb83304107100, but I must have been too tired. I just reverted that commit, and now the test passes locally.
Comment #27
smustgrave commentedAll threads appear to still be answered.
Applied patch locally and tested some paths /admin/structure/block/block-content and /admin/structure/block/block-content/types and I still get the warning message as expected.
Failure appears to be random ckeditor5 and unrelated to this issue.
Can we update the change record to include the changes here?
Then think good to mark RTBC.
Comment #28
benjifisher@smustgrave:
Thanks for testing.
Did you consider the question about tests in #24? Do we want to keep the second unit test or the kernel test?
I updated the change record. While I was doing that, I noticed that one of the redirect controllers referred to #2317981: Move block content edit and delete routes under admin/content/block to improve IA for editors and fix breadcrumbs instead of the change record, so I updated the controller and the related test.
Comment #29
benjifisherComment #30
smustgrave commentedPersonally for me I'm more a fan of kernel tests. So if we are voting that would be mine.
Comment #31
smustgrave commentedJust to remove 2nd unit test per #28. Can RTBC after that.
Comment #32
benjifisherI removed the second unit test. Based on #31, I am setting the status to RTBC.
Comment #33
benjifisherWhen I created this issue, I thought that #3318112: [PP1] Move "Block layout" from Structure to Appearance would be fixed first. That seems unlikely now, so I am rewriting the proposed resolution: this issue adds a new helper class, but does not replace what would have been added by that issue.
Comment #34
larowlanLooks like the MR is failing with PHPCS checks
Comment #36
benjifisher@Rassoni:
Thanks for fixing the CodeSniffer issues. Back again to RTBC, based on #31. That should trigger a retest.
Comment #37
benjifisherThe failing test is Drupal\BuildTests\Composer\Component\ComponentsIsolatedBuildTest. It does not seem related, and it passes locally, so let's keep the status at RTBC.
Comment #39
larowlanLeft some comments on the MR, I think we can push the 'auto detect child paths' idea to a follow up and get this in.
Fine to self RTBC
Comment #42
larowlanOn second thoughts, just going to get this in by making the change myself at commit time
Committed to 11.x and backported to 10.1.x
Fixed on commit:
Opened #3364747: Attempt to auto-detect child paths of deprecated routes and add redirects for follow-up
Comment #43
larowlanComment #45
benjifisher@larowlan:
I am glad to see this get in!
Can you add a link to the follow-up issue you created?
I think we need to include
$block_contentin the parameter list, with its type hint, so that we can have the same access checks on the BC route as on the original. In other words, it is used implicitly.OTOH, maybe we should not do access checks at all on the BC route. (shrug)
The doc block now says "an deprecated". Oh, well.
Comment #46
larowlanFollow-up is in #42 #3364747: Attempt to auto-detect child paths of deprecated routes and add redirects
I'll see if we can hotfix the deprecated, I assume the `an` was for reading it as `an at deprecated` and now that makes no sense without the `at`
Comment #49
larowlanI hotfixed the an > a