Problem/Motivation
When reinstalling a website with default content using layout builder overrides, there are access problem when editing inline blocks due to #3047022: Layout builder fails to assign inline block access dependencies for the overrides section storage on entities with pending revisions (and #3090200: Paragraph view access check using incorrect revision of its parent, leading to issues viewing paragraphs when reverted host entities or content moderation is used 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"
},
| Comment | File | Size | Author |
|---|---|---|---|
| #17 | default_content-3359137-17.patch | 5.44 KB | drdam |
| #3 | default_content-3359137-3.patch | 6.12 KB | grimreaper |
Issue fork default_content-3359137
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
grimreaperUploading patch for easier Composer usage.
Thanks for the review.
Comment #4
andypostcould use https://www.php.net/manual/en/language.oop5.decon.php#language.oop5.deco... to simplify definition above
Comment #5
grimreaperThanks @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?
Comment #6
andypostGood point, yes, we need to keep BC!
Is there a way to add basic test for new class?
Comment #7
berdirI did'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.
Comment #8
grimreaperHi,
Thanks both of you for your feedbacks.
Me too, so I may have taken the problem in a wrong way.
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.
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.
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.
Comment #9
berdir> 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.
Comment #10
jcandan commentedSpecified this patch along with those listed in the description:
With this, I successfully ran
drush dcer node ${NID} --folder=modules/custom/my_custom/content/, imported my database without the content, enabledmy_custommodule, and the content is there.THANK YOU for these patches!
Note: I found this while trying to get past the issue described in #3160146. I did not specifically check for the issue described here.
Comment #11
jayhuskinsI'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.
Comment #12
berdirThis depends on another issue and can't be RTBC yet.
And yes, as discussed, it looks like this might be a workaround for an issue in LB itself, but not using that
Comment #14
strykaizerUpdated MR to work with 11.3
Comment #15
berdirSee #3062819: Duplicated and new entities with inline blocks do not duplicate their inner blocks and/or track their usage, I think fixing that as I proposed will resolve this.
Comment #17
drdam commentedUpdated patch