Problem/Motivation
- The
block_contentmodule is a block factory. It creates blocks plugins by deriving over reusable Block Content entities (\Drupal\block_content\Entity\BlockContent). - The
blockmodule mainly offers block placement functionality.
Normally, block_content.module should not need block.module in order to function properly. The blocks produced by block_content can be placed on page by Layout Builder, Display Suite, Panels and even... (core) Block module.
But there are some dependencies on block.module exposed in block_content.module:
- The
administer blockspermission. - The
block.admin_displayroute. - Unnecessarily installing block in tests
- Redirects for insert/update with BlockContent entity form
- Delete form and delete hook
- ...anything else?
But, I think the above, dependencies were just a compromise, inherited from earlier Drupal versions. I see them only polluting the intra-module relationships by an unneeded dependency.
Proposed resolution
Now that we have decoupled block_content from the block library, I believe we can remove dependency
To be discussed...
- Move
block.admin_displayroute in core? - Believe this is no longer needed - What about the shared permission? - Believe this is no longer needed
Remaining tasks
- Review outline in #3206952-22: Remove block.module dependency from block_content
- Review proposed MR
User interface changes
None
API changes
Move appropriate customisations to Block or Block Content modules.
Add accommodations to testing in Block Content that relies on block placement to avoid block.module
Data model changes
None
Release notes snippet
@todo
| Comment | File | Size | Author |
|---|---|---|---|
| #29 | 3206952-nr-bot.txt | 91 bytes | needs-review-queue-bot |
Issue fork drupal-3206952
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 #2
claudiu.cristeaI have the same issue with the contrib
simple_block, see https://www.drupal.org/project/simple_block/issues/3206088Comment #7
smustgrave commentedBelieve this will be covered in https://www.drupal.org/project/drupal/issues/1975064 and https://www.drupal.org/project/ideas/issues/3318110
Comment #9
smustgrave commentedNow that we have moved block_content we may be able to remove the dependency.
Comment #11
smustgrave commentedSo tested removing block as a dependency and can already see failures happening.
Seems like it would be more effort to remove block. There's also a preDelete call on the entity
Which seems dependent on block.
Going to say this works as designed if anyone disagrees please reopen explaining why
Thanks!
Comment #12
mstrelan commentedI think it should still be possible to remove the dependency on block.module, it just may need a bit of refactoring.
The \Drupal\block_content\BlockContentInterface::getInstancesmethod (used inpreDelete) provides special handling for block.module but completely ignores layout builder. It probably makes more sense to have a separate service for this integration, and the block instance deletion should probably be implemented in a hook. In other words, theBlockContententity should have no awareness ofBlockentities.Comment #13
smustgrave commentedLets see if anyone picks it up.
Comment #14
smustgrave commentedComment #15
smustgrave commentedComment #16
larowlanWe haven't addressed #11 and #12 yet.
Which leads me to believe we're missing test coverage for that when block.module is disabled.
\Drupal\block_content\Entity\BlockContent::getInstances should hard fail when the block entity-type doesn't exist.
There's also a reference to block.admin_library in block_content.links.action.yml - it would be good to confirm that doesn't cause any side-effects.
Comment #17
dpiWorking on this...
Comment #18
acbramley commentedThe BlockContentViewBuilder is also tightly coupled to Block module.
And more info in #2666578: Block Content entities have no Contextual links when rendered outside of Block config entity
Comment #19
acbramley commentedMore coupling in BlockContentForm https://git.drupalcode.org/project/drupal/-/blob/11.x/core/modules/block...
Comment #20
acbramley commentedComment #22
dpiCreated a new MR @ https://git.drupalcode.org/project/drupal/-/merge_requests/12156
Implementation notes
BlockContentBrokenTestin block content is testing against\Drupal\Core\Block\Plugin\Block\Broken(in core), this core class relies onadminister blockspermission defined by block. So I've createdadminister_blocks_permission_testtest module to also define aadminister blockspermission so we can test without block.module. I've created #3524897: [PP-1] Dependency from core block plugin to block module to address this problem where core is depending on a block.module permission, as of writing currently postponed on #1537198: Add a Production/Development toggleBlockBlockContentHooks) which is conditionally enabled depending on whether block_content.module is enabled. This hooks class has form alter and button callbacks, formally located in Block Contents'\Drupal\block_content\BlockContentForm. Associated tests have been moved to Block.module'sBlockContentSaveFormRedirectTest.\Drupal\block_content\Entity\BlockContent::getInstancesand\Drupal\block_content\Form\BlockContentDeleteFormmoved to the three classes adjacent to\Drupal\block_content\BlockUsage\BlockContentBlockUsageDrupal\block_content\BlockUsage\BlockContentBlockUsageInterfaceBlockContentCompilerPass). See new test coverage atBlockContentBlockUsageTestBlockContentDeleteFormandBlockContent::preDeleterequire.BlockContentDeleteFormandBlockContent::preDeleteare still retain responsibility for calling out to this service.BlockContentUsageListfinal for now. It should be un-finalised only if an interface is extracted, in the future.\Drupal\block_content\Entity\BlockContent::getInstancesdeprecated, change notice at https://www.drupal.org/node/3523951BlockContentBlockHooks) which is conditionally enabled depending on whether block.module is enabled. This hooks class provides the existing hooks to modify theblockhook_theme/template and modify block config entity operations. Hopefully the block preprocess hook can be moved out when #3003610: Remove block.module dependency from Layout Builder finishes decouplingblockhook_theme/template from block.module to core/system.module.#[Hook('help')]modified with various decouplings and variable-izing permission names. One piece of help text used to referenceadminister blocks, but was incorrect since permission changes in #1975064: Add more granular block content permissions.BlockContentBlock::buildto no longer rely onadminister blocks, but onUrl->access(). Looks like the permission was no longer correct anyway, since permission changes in #1975064: Add more granular block content permissions.\Drupal\Tests\block_content\Functional\BlockContentTestBase.BlockContentTestBase. This includesadminister blocks, among others.placeBlockto place title/actions/tasks on pages, which tests used to click links. However this method requires block.module, which we're trying to prevent unnecessary dependencies on. So I've introduced thenavigation_variant_testtest module which can render navigation blocks without block.module. I've created #3524985: Reduce dependency on block.module in tests to expand usage of this technique so other parts of core can reduce need of block.module viaplaceBlock/drupalPlaceBlock.Comment #23
dpiClarifying title: its block module (not block config or theme_hook:block).
I think though we're not "removing" a dependency, but rather block or block content are conditionally enhancing the other module depending on install state.
-
Updated issue summary a bit.
Comment #24
acbramley commentedI've gone through the MR quite thoroughly and generally +1 this overall approach although it is quite complicated and may be hard for some devs to grok, especially the compiler pass stuff (queue many "why isn't this working?!")
My main concerns are:
1. The administer_blocks_permission_test module, although very minor it just doesn't feel right to add a duplicate permission, this is a big nit picky though
2. navigation_variant_test - now tests that just needed 1 block get all the additional elements rendered. Again this may be minor. I haven't ever looked into DisplayVariant plugins before though so thanks for the learning :)
Comment #25
dpiThanks, some actionables there for me.
Comment #26
larowlanLeft some questions on the MR
Comment #27
dpiA couple q's for @larowlan. Remaining open threads I dont see as actionable/my implementation notes.
Comment #28
dpiComment #29
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 necessarily 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.