Update inline block usage on import

Created on 9 May 2023, about 1 year ago
Updated 31 January 2024, 5 months ago

Problem/Motivation

When reinstalling a website with default content using layout builder overrides, there are access problem when editing inline blocks due to πŸ› Layout builder fails to assign inline block access dependencies for the overrides section storage on entities with pending revisions Needs work (and πŸ› Paragraph access check using incorrect revision of its parent, leading to issues editing and viewing paragraphs when content moderation is involved. Needs work if using paragraphs in inline blocks).

I tried to apply patches from those issues. It was then ok for paragraphs but not for inline blocks with media, even after reinstallation.

I dug to see were the problem was coming from and found out it was due to the inline_block_usage table not populated when default content are imported.

Proposed resolution

I initially made a service to insert data into the inline block usage table, then wanting something generic, I saw that Default Content provides events. So I converted that into a generic optional event subscriber.

Finally using only this event subscriber, I no more need the patches on Core or Paragraphs and after reinstallation it is ok out-of-the-box.

I will provide the MR.

For info in my default_content usage, here are the patches I have applied:

            "drupal/default_content": {
                "1 - Import should overwrite files - https://www.drupal.org/project/default_content/issues/3200212#comment-14332801": "https://www.drupal.org/files/issues/2021-12-08/default_content-3200212.patch",
                "2 - Don't add translation, if exist - https://www.drupal.org/project/default_content/issues/3176839#comment-13859359": "https://www.drupal.org/files/issues/2020-10-14/default_content-3176839-2.patch",
                "3 - Add a Normalizer and Denormalizer to support Layout Builder - https://www.drupal.org/project/default_content/issues/3160146#comment-14814050": "https://www.drupal.org/files/issues/2022-12-06/default_content-3160146-53.patch"
            },
✨ Feature request
Status

RTBC

Version

2.0

Component

Code

Created by

πŸ‡«πŸ‡·France Grimreaper France πŸ‡«πŸ‡·

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

Comments & Activities

  • Issue created by @Grimreaper
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    13 pass
  • @grimreaper opened merge request.
  • Issue was unassigned.
  • Status changed to Needs review about 1 year ago
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    13 pass
  • πŸ‡«πŸ‡·France Grimreaper France πŸ‡«πŸ‡·

    Uploading patch for easier Composer usage.

    Thanks for the review.

  • πŸ‡«πŸ‡·France andypost
    +++ b/src/EventSubscriber/InlineBlockUsageFixer.php
    @@ -0,0 +1,156 @@
    +    EntityTypeManagerInterface $entityTypeManager,
    +    ?InlineBlockUsageInterface $usage,
    +    ?SectionStorageManagerInterface $sectionStorageManager
    

    could use https://www.php.net/manual/en/language.oop5.decon.php#language.oop5.deco... to simplify definition above

  • πŸ‡«πŸ‡·France Grimreaper France πŸ‡«πŸ‡·

    Thanks @andypost for the feedback and pointing me to a constructor syntax I forgot or didn't know it exists.

    But that would raise the PHP minimum version required by the module. And as the module still supports Drupal 9, I am not sure it is a possible change to do right now?

  • πŸ‡«πŸ‡·France andypost

    Good point, yes, we need to keep BC!

    Is there a way to add basic test for new class?

  • πŸ‡¨πŸ‡­Switzerland Berdir Switzerland

    I don't look at the patch yet and may layout builder understanding is very limited. I don't quite understand why we need to help it maintain its internal info, seems like a workaround for limitations in layout builder itself?

    also, the layout builder integration isn't even committed yet, that should be the focus, specifically in regards to tests which it hasn't yet. And if this is really required for it to work properly, it could also be part of the same issue.

  • πŸ‡«πŸ‡·France Grimreaper France πŸ‡«πŸ‡·

    Hi,

    Thanks both of you for your feedbacks.

    and may layout builder understanding is very limited

    Me too, so I may have taken the problem in a wrong way.

    seems like a workaround for limitations in layout builder itself?

    Yes, it may be a workaround for a core bug.

    The only place were the inline block usage is inserting entries inthis table is in InlineBlockEntityOperations::saveInlineBlockComponent(), which is only call in InlineBlockEntityOperations::handlePreSave() which is call in layout_builder_entity_presave. So I guess that it should work out of the box.

    But in InlineBlockEntityOperations::saveInlineBlockComponent(), there is an if statement before inserting in the table. So I guess the way default_content is exporting Layout Builder data may be wrong (at least when reinstalling a website). And in this case it should be handled in the other issue.

    Is there a way to add basic test for new class?

    Before doing that, like @Berdir pointed out, it may be a workaround for either a core bug or a bug in the other default_content issue about Layout Builder.

    also, the layout builder integration isn't even committed yet, that should be the focus, specifically in regards to tests which it hasn't yet. And if this is really required for it to work properly, it could also be part of the same issue.

    Agreed. I needed a generic quick fix now for multiple projects using both Layout Builder and Default Content and I didn't wanted to risk breaking the MR on the other issue with this change in case people get patches for Composer using the MR URL directly.

  • πŸ‡¨πŸ‡­Switzerland Berdir Switzerland

    > Agreed. I needed a generic quick fix now for multiple projects using both Layout Builder and Default Content and I didn't wanted to risk breaking the MR on the other issue with this change in case people get patches for Composer using the MR URL directly.

    That makes perfect sense, thanks contributing and working on this publicly.

  • Status changed to RTBC 11 months ago
  • πŸ‡ΊπŸ‡ΈUnited States jcandan

    Specified this patch along with those listed in the description:

                "drupal/default_content": {
                    "1 - Import should overwrite files - https://www.drupal.org/project/default_content/issues/3200212#comment-14332801": "https://www.drupal.org/files/issues/2021-12-08/default_content-3200212.patch",
                    "2 - Don't add translation, if exist - https://www.drupal.org/project/default_content/issues/3176839#comment-13859359": "https://www.drupal.org/files/issues/2020-10-14/default_content-3176839-2.patch",
                    "3 - Add a Normalizer and Denormalizer to support Layout Builder - https://www.drupal.org/project/default_content/issues/3160146#comment-14814050": "https://www.drupal.org/files/issues/2022-12-06/default_content-3160146-53.patch",
                    "4 - Update inline block usage on import - https://www.drupal.org/project/default_content/issues/3359137#comment-15042582": "https://www.drupal.org/files/issues/2023-05-09/default_content-3359137-3.patch"
                },
    

    With this, I successfully ran drush dcer node ${NID} --folder=modules/custom/my_custom/content/, imported my database without the content, enabled my_custom module, and the content is there.

    THANK YOU for these patches!

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

    I'm running into a similar situation except instead of using Default content, I'm migrating inline blocks. I wonder if there's a deeper issue here.

Production build 0.69.0 2024