Remove block dependency from block_content

Created on 2 April 2021, about 3 years ago
Updated 3 January 2024, 6 months 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

Now that we have decoupled block_content from the block library, believe we can remove dependency

To be discussed...

  • Move block.admin_display route in core? - Believe this is no longer needed
  • What about the shared permission? - Believe this is no longer needed

Remaining tasks

Agree on approach
Review

User interface changes

NA

API changes

NA

Data model changes

NA

Release notes snippet

NA

πŸ“Œ Task
Status

Needs work

Version

11.0 πŸ”₯

Component
Block contentΒ  β†’

Last updated 5 days 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 about 1 year ago
    29,462 pass, 17 fail
  • last update about 1 year ago
    29,462 pass, 17 fail
  • Status changed to Closed: works as designed about 1 year 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 about 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Lets see if anyone picks it up.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave
  • Status changed to Needs review 6 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave
  • Status changed to Needs work 6 months 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
    
Production build 0.69.0 2024