Clear pending changes on config import

Created on 21 September 2022, almost 3 years ago
Updated 16 March 2024, over 1 year ago

Problem/Motivation

When we import the drupal configuration, if there are changes in the layout builder form, it is not displayed correctly.

Steps to reproduce

  1. Create a simplytest.
  2. Enable modules: config, layout_builder and layout_discovery.
  3. Enable the "Use Layout Builder" option (admin/structure/types/manage/page/display).
  4. Make a change, for example, add the title block and save (admin/structure/types/manage/page/display/default/layout).
  5. Export configuration (admin/config/development/configuration/full/export).
  6. Make a change, e.g. delete title block and save (admin/structure/types/manage/page/display/default/layout).
  7. Enter the layout builder editing form and do not click on the "save layout" or "discard changes" buttons admin/structure/types/manage/page/display/default/layout).
  8. Import configuration and reload the layout administration page (admin/structure/types/manage/page/display/default/layout). The imported configuration is not displayed correctly..
๐Ÿ“Œ Task
Status

Active

Version

11.0 ๐Ÿ”ฅ

Component
Layout builderย  โ†’

Last updated 10 days ago

Created by

๐Ÿ‡ช๐Ÿ‡ธSpain javier_rey

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

Comments & Activities

Not all content is available!

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

  • ๐Ÿ‡ณ๐Ÿ‡ฟNew Zealand danielveza Brisbane, AU

    I wonder if we could add a ConfigEvents::IMPORT EventSubscriber and use ConfigImporterEvent::getChangelist to find any displays that are going to be updated, and clear the tempstore for just those displays.

    I guess we need to consider if deleting the tempstore on import is considered data loss or not. If it's something that we don't want to implement in core I'm pretty sure this would be a pretty easy contrib module to make.

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium herved

    We ran into this issue after switching to layout_builder on a project.
    Itโ€™s made worse by the fact that the tempstore is auto-saved whenever you visit a layout builder display (see Drupal\layout_builder\EventSubscriber\PrepareLayout::onPrepareLayout), unlike views for example. Those expire after a week. So when working on displays, you almost always end up with tempstore entries locally, leading to the issues below.

    This really feels like a bug for two reasons:
    1. It causes confusion, since changes are not visible on the layout builder display pages after a config:import
    2. Deleting a computed / extra field / layout etc, then accessing the layout builder display causes a fatal error because the corresponding plugin cannot be foundโ€”and layout builder cannot recover.

    Here is a possible solution, crude but effective:

    /**
     * Implements hook_cache_flush().
     */
    #[Hook('cache_flush')]
    public function cacheFlush(): void {
      // Clear layout_builder defaults section storage tempstore on cache flush.
      // @see https://www.drupal.org/i/3310897
      \Drupal::database()
        ->delete('key_value_expire')
        ->condition('collection', 'tempstore.shared.layout_builder.section_storage.defaults')
        ->execute();
    }
    
Production build 0.71.5 2024