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

Issue fork drupal-3346394

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

smustgrave created an issue. See original summary.

smustgrave’s picture

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

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

_shy’s picture

Title: Deprecation BlockController::Add » Deprecation BlockContentController::Add
_shy’s picture

Status: Active » Needs work

I'm not sure if the function \Drupal\Core\Entity\Controller\EntityController::addPage() fits for that because this function has an argument $entity_type_id that should be passed from the route.

Or, I just missed something important here.

joachim’s picture

Title: Deprecation BlockContentController::Add » Remove BlockContentController::Add

There is no need to deprecate - core controllers aren't part of the api unless marked as such.

smustgrave’s picture

Pushed 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.

smustgrave’s picture

For the slack help.

larowlan’s picture

I 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.

smustgrave’s picture

Issue summary: View changes
smustgrave’s picture

Issue summary: View changes
block_content.add_form: '/block/add/{block_content_type}'
block_content.add_page: /block/add
block_content.type_add: /admin/structure/block-content/add
block_content.type_add.bc: /admin/structure/block/block-content/types/add

block_content.add_form: '/block/add/{block_content_type}'
block_content.add_page: /block/add
block_content.type_add: /admin/structure/block-content/add
block_content.type_add.bc: /admin/structure/block/block-content/types/add

So 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

smustgrave’s picture

Assigned: Unassigned » smustgrave

Will pick back up tomorrow

smustgrave’s picture

smustgrave’s picture

Assigned: smustgrave » Unassigned

Think need approval on the removal of the destination parameter.

The failures I currently have no clue about. Clearly missing a route setting

acbramley’s picture

This 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::addPage has 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.

acbramley’s picture

We 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

acbramley’s picture

Title: Remove BlockContentController::Add » Remove BlockContentController::add via the AdminHtmlRouteProvider route provider
Issue summary: View changes
acbramley’s picture

Title: Remove BlockContentController::add via the AdminHtmlRouteProvider route provider » Replace BlockContentController::add with EntityController::addPage via the AdminHtmlRouteProvider route provider
acbramley’s picture

Pushed a WIP of what I've got so far, things are a bit more complicated because of 2 things:

1. BlockContentController::addForm has 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 from template_preprocess_block_content_add_list currently which is not compatible with the generic entity_add_list that EntityController uses.

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 ::getRoutes to swap the route names.

acbramley’s picture

Based 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

acbramley’s picture

Issue summary: View changes
acbramley’s picture

Issue summary: View changes
acbramley’s picture

Title: Replace BlockContentController::add with EntityController::addPage via the AdminHtmlRouteProvider route provider » [PP-2] Replace BlockContentController::add with EntityController::addPage via the AdminHtmlRouteProvider route provider
Issue summary: View changes
Status: Needs work » Postponed
Related issues: +#3530654: BlockContentType should implement EntityDescriptionInterface, +#3196798: Fix EntityController::addPage so bundles are sorted by label and not ID
acbramley’s picture

Title: [PP-2] Replace BlockContentController::add with EntityController::addPage via the AdminHtmlRouteProvider route provider » [PP-1] Replace BlockContentController::add with EntityController::addPage via the AdminHtmlRouteProvider route provider
acbramley’s picture

Issue summary: View changes
acbramley’s picture

Issue summary: View changes
StatusFileSize
new21 KB
new16.38 KB
acbramley’s picture

Title: [PP-1] Replace BlockContentController::add with EntityController::addPage via the AdminHtmlRouteProvider route provider » Replace BlockContentController::add with EntityController::addPage via the AdminHtmlRouteProvider route provider
Issue summary: View changes
Status: Postponed » Needs work

This should be green now, we just need to action the route rename.

acbramley’s picture

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

Updated the route names, also added test coverage for the query param redirection stuff in EntityController::addPage

acbramley’s picture

Status: Needs review » Needs work

The route renaming is causing some issues with JSON:API Rest tests and Link relations.

acbramley’s picture

Status: Needs work » Needs review

So 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.

smustgrave’s picture

Changes look good to me but I don't think I can mark it.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Don't want it to stale so since the latest changes weren't me going to mark it now.

berdir’s picture

Status: Reviewed & tested by the community » Needs work

template_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.

berdir’s picture

Forget 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()

acbramley’s picture

Status: Needs work » Needs review

Good point, added it back with a deprecation

berdir’s picture

Status: Needs review » Needs work

Added a review.

acbramley’s picture

Status: Needs work » Needs review

Addressed all feedback, thanks for catching the template issue.

berdir’s picture

Status: Needs review » Reviewed & tested by the community

BC 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.

catch’s picture

Status: Reviewed & tested by the community » Needs work

Had one question on the MR about the parameter change on EntityController - but also there are merge conflicts in the MR.

acbramley’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Feedback on this one appears to be addressed

berdir’s picture

Had 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.

  • catch committed 45faba8d on 11.x
    Issue #3346394 by smustgrave, _shy, larowlan, aaronmchale, acbramley,...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 11.x, thanks!

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.