Why block_content depends on block?

Created on 2 April 2021, about 4 years ago
Updated 6 June 2023, almost 2 years ago

Problem/Motivation

  1. The block_content module is a block factory. It creates blocks by deriving over content entities of type block_content.
  2. The block module mainly offers a 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 blocks permission.
  • The block.admin_display route.
  • ...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.

Steps to reproduce

N/A

Proposed resolution

To be discussed...

  • Move block.admin_display route in core?
  • What about the shared permission?

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

πŸ“Œ Task
Status

Active

Version

11.0 πŸ”₯

Component
Block contentΒ  β†’

Last updated 1 day ago

Created by

πŸ‡·πŸ‡΄Romania claudiu.cristea Arad πŸ‡·πŸ‡΄

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Now that we have moved block_content we may be able to remove the dependency.

  • last update almost 2 years ago
    29,462 pass, 17 fail
  • last update almost 2 years ago
    29,462 pass, 17 fail
  • Status changed to Closed: works as designed almost 2 years ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    So 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

        parent::preDelete($storage, $entities);
    
        /** @var \Drupal\block_content\BlockContentInterface $block */
        foreach ($entities as $block) {
          foreach ($block->getInstances() as $instance) {
            $instance->delete();
          }
        }
    

    Which seems dependent on block.

    Going to say this works as designed if anyone disagrees please reopen explaining why

    Thanks!

  • πŸ‡¦πŸ‡ΊAustralia mstrelan

    I 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::getInstances method (used in preDelete) 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, the BlockContent entity should have no awareness of Block entities.

  • Status changed to Active almost 2 years ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Lets see if anyone picks it up.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave
  • Pipeline finished with Failed
    over 1 year ago
    Total: 608s
    #66951
  • Pipeline finished with Success
    over 1 year ago
    Total: 566s
    #66957
  • Status changed to Needs review over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave
  • Status changed to Needs work over 1 year ago
  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

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

    block_content_add_action:
      route_name: block_content.add_page
      title: 'Add content block'
      appears_on:
        - block.admin_library ## here
        - entity.block_content.collection
      class: \Drupal\block_content\Plugin\Menu\LocalAction\BlockContentAddLocalAction
    
  • Assigned to dpi
  • πŸ‡¦πŸ‡ΊAustralia dpi Perth, Australia

    Working on this...

  • πŸ‡¦πŸ‡ΊAustralia acbramley

    The BlockContentViewBuilder is also tightly coupled to Block module.

    And more info in πŸ› Block Content entities have no Contextual links when rendered outside of Block config entity Closed: won't fix

  • πŸ‡¦πŸ‡ΊAustralia acbramley
  • Merge request !12156Decouple Block from Block Content β†’ (Open) created by dpi
  • Pipeline finished with Success
    15 days ago
    Total: 539s
    #499753
  • πŸ‡¦πŸ‡ΊAustralia dpi Perth, Australia

    Created a new MR @ https://git.drupalcode.org/project/drupal/-/merge_requests/12156

    • Generally a lot of reduction and dependency on Block between the two modules, and especially in tests.
    • A new small service for usage.
    • A new core test module to test navigation blocks, without needing block.module. See also πŸ“Œ Reduce dependency on block.module in tests Active .

    Implementation notes

  • BlockContentBrokenTest in block content is testing against \Drupal\Core\Block\Plugin\Block\Broken (in core), this core class relies on administer blocks permission defined by block. So I've created administer_blocks_permission_test test module to also define a administer blocks permission so we can test without block.module. I've created πŸ› Dependency from core block plugin to block module Active to address this problem where core is depending on a block.module permission, as of writing currently postponed on ✨ Add a Production/Development Toggle To Core Needs work
  • A new hooks class added to block.module (BlockBlockContentHooks) which is conditionally enabled depending on whether block_content.module is enabled. This hooks class has form alter and button callbacks, which functionally was formally located in Block Contents' \Drupal\block_content\BlockContentForm. Associated tests have been moved to Block.module's BlockContentSaveFormRedirectTest.
  • The functionality formerly provided by \Drupal\block_content\Entity\BlockContent::getInstances and \Drupal\block_content\Form\BlockContentDeleteForm moved to the three classes adjacent to \Drupal\block_content\BlockUsage\BlockContentBlockUsage
    • I considered making this a feature of block.module, but decided that BlockContent should still be responsible for these messages, but split out of the entity class.
    • A service was created, accessible at Drupal\block_content\BlockUsage\BlockContentBlockUsageInterface
    • The service is conditionally available, depending on whether block.module is also installed (BlockContentCompilerPass). See new test coverage at BlockContentBlockUsageTest
    • A mulipurpose iterable/countable class provides the necessary block config producing and efficient counting functionality that BlockContentDeleteForm and BlockContent::preDelete require.
    • BlockContentDeleteForm and BlockContent::preDelete are still retain responsibility for calling out to this service.
    • Ive made BlockContentUsageList final for now. It should be un-finalised only if an interface is extracted, in the future.
    • \Drupal\block_content\Entity\BlockContent::getInstances deprecated, change notice at https://www.drupal.org/node/3523951 β†’
  • A new hooks class added to block_module.module (BlockContentBlockHooks) which is conditionally enabled depending on whether block.module is enabled. This hooks class provides the existing hooks to modify the block hook_theme/template and modify block config entity operations. Hopefully the block preprocess hook can be moved out when πŸ“Œ Remove block.module dependency from Layout Builder Needs work finishes decoupling block hook_theme/template from block.module to core/system.module.
  • BlockContent's #[Hook('help')] modified with various decouplings and variable-izing permission names. One pieces of help text used to reference administer blocks, but was incorrect since permission changes in ✨ Add more granular block content permissions Fixed .
  • Changed BlockContentBlock::build to no longer rely on administer blocks, but on Url->access(). Looks like the permission was no longer correct anyway, since permission changes in ✨ Add more granular block content permissions Fixed .
  • Generally, many Block Content Kernel and Functional tests no longer need block.module to be installed, both explicitely and implicitely by \Drupal\Tests\block_content\Functional\BlockContentTestBase.
    • I re-evaluated all Kernel/Functional tests in Block Content, and updated them the explicit permissions the test user needs, instead of blanket permissions from BlockContentTestBase. This includes administer blocks specifically.
    • There were many uses of placeBlock to 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 the navigation_variant_test test module which can render navigation blocks without block.module. I've created πŸ“Œ Reduce dependency on block.module in tests Active to expand usage of this method so other parts of core can reduce need of block.module via placeBlock.
  • Pipeline finished with Success
    14 days ago
    Total: 1019s
    #499792
  • Pipeline finished with Failed
    14 days ago
    Total: 562s
    #499806
  • πŸ‡¦πŸ‡ΊAustralia dpi Perth, Australia

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

  • πŸ‡¦πŸ‡ΊAustralia acbramley

    I'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 :)

  • πŸ‡¦πŸ‡ΊAustralia dpi Perth, Australia

    Thanks, some actionables there for me.

  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    Left some questions on the MR

  • πŸ‡¦πŸ‡ΊAustralia dpi Perth, Australia

    A couple q's for @larowlan. Remaining open threads I dont see as actionable/my implementation notes.

  • πŸ‡¦πŸ‡ΊAustralia dpi Perth, Australia
  • Pipeline finished with Failed
    8 days ago
    Total: 162s
    #505452
  • Pipeline finished with Success
    8 days ago
    Total: 508s
    #505455
  • Production build 0.71.5 2024