Handle update and delete of Block component config entities

Created on 30 October 2024, 6 months ago

Overview

Block components have config entities for each plugin created automatically on cache clear. However, block plugins that do not exist do not have components deleted, nor are existing block component config entities updated once they have been created.

Proposed resolution

Delete block component config entities once the plugin (or derivative) no longer exists.
Decide when and how to update block component config entities when changes occur.

User interface changes

πŸ“Œ Task
Status

Active

Version

0.0

Component

Config management

Created by

πŸ‡¬πŸ‡§United Kingdom longwave UK

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

Merge Requests

Comments & Activities

  • Issue created by @longwave
  • πŸ‡¬πŸ‡§United Kingdom longwave UK
  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    πŸ‘

  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί
  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    This should add \Drupal\Tests\experience_builder\Kernel\Plugin\ExperienceBuilder\ComponentSource\BlockComponentTest and test β€” by for example deleting a Menu config entity, which will result in \Drupal\system\Plugin\Derivative\SystemMenuBlock deriving one fewer block.

    I bet there will be config dependency-related challenges πŸ˜‡ In fact … I see that the necessary config dependencies are missing currently. For example:

    uuid: 784eab71-dbfa-49da-b932-dc703a5de2f8
    langcode: en
    status: true
    dependencies: {  }
    label: 'Administration block'
    id: block.system_menu_block.admin
    provider: system
    source: block
    category: Menus
    settings:
      plugin_id: 'system_menu_block:admin'
      default_settings:
        id: 'system_menu_block:admin'
        label: Administration
        label_display: ''
        provider: system
        level: 1
        depth: 0
        expand_all_items: true
    

    😱

    That

    dependencies: {  }
    

    should be

    dependencies:
      config:
        - system.menu.admin
    

    That is an oversight in bug when Block support was first added in πŸ“Œ Add support for Blocks as Components Active .

  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί
  • πŸ‡¬πŸ‡§United Kingdom longwave UK

    Adding dependencies fixes the menus case, but there are other cases where a block might change or disappear which needs additional work and test coverage.

  • Pipeline finished with Failed
    15 days ago
    Total: 1783s
    #471473
  • Pipeline finished with Failed
    12 days ago
    Total: 253s
    #472976
  • Pipeline finished with Failed
    12 days ago
    Total: 373s
    #472980
  • Pipeline finished with Failed
    12 days ago
    Total: 1490s
    #472983
  • Pipeline finished with Canceled
    12 days ago
    Total: 126s
    #473036
  • πŸ‡¬πŸ‡§United Kingdom longwave UK

    Added additional test coverage for uninstalling a module that provides a block, and updating a block label.

    There is the possibility that a block that previously met requirements (ie. it must be fully validatable) stops meeting those requirements, but is this realistically a case we need to handle? I added protection for it by deleting the block component if a reason exists that it is not valid, but unsure if it is worth contriving test coverage for this case.

  • Pipeline finished with Failed
    12 days ago
    Total: 1512s
    #473038
  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    Yay for πŸ“Œ Introduce unit test coverage for both ComponentSource plugins (Block + SDC) Active providing the appropriate place for this new test coverage!

    I found a few problems in the MR, but I'm wondering if that's my brain still readjusting from the weekend? πŸ™ˆ

  • πŸ‡¬πŸ‡§United Kingdom longwave UK

    Once config entities get dependencies, they automatically get deleted if the dependent entity is deleted - ie. if we depend on a menu and that menu ceases to exist, then the component will be deleted too. But we explicitly wanted to add the dependencies here, so what should we do? Prevent the menu from being deleted, or only have a soft dependency on the menu existing?

  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    Right. πŸ€”

    What I'd like to see in the test coverage is β€” somehow β€” verifying that there's a confirmation dialog when humans try to delete a menu, which would then inform the user that they're making this component obsolete.

    But we explicitly wanted to add the dependencies here, so what should we do? Prevent the menu from being deleted, or only have a soft dependency on the menu existing?

    I don't think we need to prevent it. But we need to ensure that we do not cascade it down: if a ContentTemplate depends on a Component that depends on a Menu, the current code is basically saying that Component and ContentTemplate will disappear on you! That's bad πŸ˜…

    I think we should implement \Drupal\Core\Config\Entity\ConfigEntityInterface::onDependencyRemoval(), to prevent that? πŸ˜‡

  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    Same exact challenge appeared over at #3519168-10: Cannot delete JS components due to component depending on them β†’ overnight! πŸ˜…

  • πŸ‡¬πŸ‡§United Kingdom longwave UK

    Yep was thinking whatever we implement here has to be done in a base class or trait and cascaded down to all our config entities.

  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    IDK about all of XB's config entities β€” perhaps only Component::onDependencyRemoval() is sufficient to start. Because … how do we remove a component instance in a Pattern, PageRegion or ContentTemplate that itself contains other component instances?! πŸ˜…

    I guess we could do it automatically if the component instance is provided by a ComponentSource that does not implement \Drupal\experience_builder\ComponentSource\ComponentSourceWithSlotsInterface?

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

    FYI In πŸ› Cannot delete JS components due to component depending on them Active I've added a fallback plugin that can step in and continue to render children when a JS component is removed if any instance exist.

  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    @longwave: I think there's still things here that make sense to land independently of πŸ› Cannot delete JS components due to component depending on them Active ?

  • Pipeline finished with Failed
    4 days ago
    Total: 2288s
    #479668
  • Pipeline finished with Failed
    4 days ago
    Total: 1779s
    #479673
Production build 0.71.5 2024