Problem/Motivation
Follow up from https://git.drupalcode.org/project/drupal/-/merge_requests/3535#note_156789
BlockContentController::add contains a lot of duplicated logic from EntityController:addPage. To support the transition fully, block_content also needs to use the AdminHtmlRouteProvider. This will allow us to remove many hardcoded routings in block_content.routing.yml as well.
Steps to reproduce
NA
Proposed resolution
- Enhance EntityController::addPage to forward query params to support the redirect logic where a single block_content bundle exists, and the theme/region query params are added.
- Deprecate the block_content_add_list template
- Remove BlockContentController::add()
- Add an add-form link template to block_content_type, this is required for the link in add_bundle_message in EntityController::addPage
- Add the AdminHtmlRouteProvider route_provider handler to the block_content entity type
- Remove duplicate existing routes from block_content.routing.yml
- Provide BC for the existing routes that differ from what the route provider adds. This is done by overriding the getRoutes method in the route providers for block_content and block_content_type
Remaining tasks
testBlockContentAddPageOrder is failing due to #3196798: Fix EntityController::addPage so bundles are sorted by label and not ID - get that in first
#3530654: BlockContentType should implement EntityDescriptionInterface - get that in next
Decide on approach for existing routes (alias or rename) - what's best for BC?
Rename routes instead of aliasing
Review
User interface changes
Changes to /block/add when there are no block types:
Before:

After:

There is also a minor change to the breadcrumb when deleting a block, it now has "Edit Block name" rather than just "Block name" in the trail.
API changes
BlockContentController::add has been removed - this is internal code not covered by the BC policy. Assume we don't need a CR for this.
block_content_add_list template has been deprecated
Data model changes
NA
Release notes snippet
NA
| Comment | File | Size | Author |
|---|---|---|---|
| #30 | block-add-after.png | 16.38 KB | acbramley |
| #30 | block-add-before.png | 21 KB | acbramley |
Issue fork drupal-3346394
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:
- 3346394-deprecation-blockcontrolleradd
changes, plain diff MR !5143
Comments
Comment #2
smustgrave commentedComment #6
_shyComment #7
_shyI'm not sure if the function
\Drupal\Core\Entity\Controller\EntityController::addPage()fits for that because this function has an argument$entity_type_idthat should be passed from the route.Or, I just missed something important here.
Comment #8
joachim commentedThere is no need to deprecate - core controllers aren't part of the api unless marked as such.
Comment #9
smustgrave commentedPushed up some attempts. But currently have an issue where
Create 2 block types
Create a test editor and assign permissions for just 1 block type
Login and try and create a block
Button doesn't do anything.
Comment #11
smustgrave commentedFor the slack help.
Comment #12
larowlanI think we'll need to make sure we keep the same route name for BC sake so if we move to a route provider, overriding the default name of entity.block_content.add_page to be the same as now will be required.
Comment #13
smustgrave commentedComment #14
smustgrave commentedSo routes end up staying the same, so we are good.
For #11 I removed the line adding the destination parameter to the "Add content block" button. Adding a block still redirect
Comment #15
smustgrave commentedWill pick back up tomorrow
Comment #17
smustgrave commentedClosed #3319145: [PP-1] Provide a "add" link template for the block_content_type entity type as a duplicate
Comment #18
smustgrave commentedThink need approval on the removal of the destination parameter.
The failures I currently have no clue about. Clearly missing a route setting
Comment #19
acbramley commentedThis has a lot of conflicts since #3461316: Redirect block/add if there is only one block type (we probably should've just done this issue instead since
EntityController::addPagehas the same redirect logic XD)It might be easiest to start from scratch here, we also need to ensure we remove the route definition in block_content.routing.yml and rename the route as per #12
I think what you were seeing in #14 was because this wasn't done.
Comment #20
acbramley commentedWe can also remove the following routes from block_content.routing.yml:
- entity.block_content.canonical
- entity.block_content.edit_form
- entity.block_content.delete_form
Those match what DefaultHtmlRouteProvider provide
Then we'll just have to alias the block_content.add_page and block_content.add_form routes
Comment #21
acbramley commentedComment #22
acbramley commentedComment #23
acbramley commentedPushed a WIP of what I've got so far, things are a bit more complicated because of 2 things:
1.
BlockContentController::addFormhas special handling for query parameters that allow a theme to be set automatically when going from the block library to add a block content entity. These query params come fromtemplate_preprocess_block_content_add_listcurrently which is not compatible with the genericentity_add_listthatEntityControlleruses.There's no easy way to override this so I've gone for a preprocess instead, we'll have to probably deprecate the block_content_add_list theme hook although I'd be worried if anyone was using this outside of core.
2. As per above all of the entity.block_content.* routes are safe to remove because they match what the route provider is generating. The 2 aliases are going to be problematic for BC even if we don't deprecate them because people might be checking the string based route name, etc. I think the easiest for this issue may be to override
::getRoutesto swap the route names.Comment #24
acbramley commentedBased on this search it looks like block_content_permissions and xp modules are the only contrib modules using this theme hook.
https://git.drupalcode.org/search?group_id=2&scope=blobs&search=block_co...
block_content_permissions is obselete according to its project page and xp is marked unsupported
Comment #25
acbramley commentedComment #26
acbramley commentedComment #27
acbramley commentedPostponed now on
#3196798: Fix EntityController::addPage so bundles are sorted by label and not ID
#3530654: BlockContentType should implement EntityDescriptionInterface
Comment #28
acbramley commentedComment #29
acbramley commentedComment #30
acbramley commentedComment #31
acbramley commentedThis should be green now, we just need to action the route rename.
Comment #32
acbramley commentedUpdated the route names, also added test coverage for the query param redirection stuff in EntityController::addPage
Comment #33
acbramley commentedThe route renaming is causing some issues with
JSON:APIRest tests and Link relations.Comment #34
acbramley commentedSo here's something kinda sneaky, we can just alias the routes the other way to make everything work again.
I've opened #3534380: [PP-2] Remove route renames and aliases for block_content to reverse this once we can do it properly.
Comment #35
smustgrave commentedChanges look good to me but I don't think I can mark it.
Comment #36
smustgrave commentedDon't want it to stale so since the latest changes weren't me going to mark it now.
Comment #37
berdirtemplate_preprocess_block_content_add_list() is being removed now, but the template is just deprecated. It won't be working without that preprocess, so we need to keep it. The same was done with template_preprocess_authorize_report for example.
To prepare for #1177762: Deprecate automatic template_preprocess discovery and 'includes'/'file' support from hook_theme(), we might still want to move it to .module. Also, in #3504381-25: [meta] Convert Template Preprocess hooks to OOP equivalent, we discussed that for .inc files, we should keep them with a deprecation message, see for example #3535680: Convert template_preprocess in views. That's not really done consistently, and it might not block getting it committed.
Comment #38
berdirForget about the moving part, this does enough. I'll take care of that in #1177762: Deprecate automatic template_preprocess discovery and 'includes'/'file' support from hook_theme()
Comment #39
acbramley commentedGood point, added it back with a deprecation
Comment #40
berdirAdded a review.
Comment #41
acbramley commentedAddressed all feedback, thanks for catching the template issue.
Comment #42
berdirBC is complicated, but I think this looks fine now. Seems a bit overkill to go to all that trouble for a template that almost certainly nobody uses, but makes sense to me that we either do it properly or not at all. If we can remove routes and controllers, then possibly we can just directly remove such a template, but that's a decision for whoever is going to commit this.
Back to RTBC.
Comment #43
catchHad one question on the MR about the parameter change on EntityController - but also there are merge conflicts in the MR.
Comment #44
acbramley commentedComment #45
smustgrave commentedFeedback on this one appears to be addressed
Comment #46
berdirHad a tricky test fail on workspaces update tests, The module install it does was running before the router table was updated and then that failed. Not exactly sure why this is triggered now.
Comment #48
catchCommitted/pushed to 11.x, thanks!