Problem/Motivation
Found in #2948828: Layout Builder's Field Blocks do not work with Quick Edit
Use patch in #6 of that issue
To reproduce:
1. Install Layout Builder module and enable "Allow each content item to have its layout customized." on the Article content type.
2. Create an article. And to view that article (e.g node/2)
3. After that click "Layout" in the tabs to edit layout for that article
4. Remove all sections
5. Add new one column section -> add body field block into that section
6. Save Layout (you will be redirected to view page for that article)
7. Click "Quick edit" for that article
Uncaught TypeError: Drupal.quickedit.editors[editorName] is not a constructor
at n.setupEditor (AppView.js?v=8.6.0-dev:141)
at AppView.js?v=8.6.0-dev:44
at Function.m.each.m.forEach (underscore.js:153)
at n.each (backbone.js:87)
at n.appStateChange (AppView.js?v=8.6.0-dev:43)
...
So each Block plugin will have its Plugin ID. Quickedit saves meta data for each field in sessionStorage. If you remove a block plugin and add the same back it will have a new plugin ID.
When you save the Layout, you will be redirected back to the canonical, and Quickedit will see that there is a new field that there is no meta data for and begin fetching it, however, since this is async, initializeEntityContextualLink() will still run and return true, and thus the contextual link will be removed from its queue (making it empty) that the fetchMissingMetadata function will try to execute once its done.
This is why the steps above fails on the first request. If you refresh that page, all metadata will be fetched and it works.
This means Quickedit assumes that you have ALL the metadata cached or none.
You can verify this by cleaning the sessionStorage, before Step 6 in the steps above, and it should work as expected.
Proposed resolution
- Implement some API to let us purge the meta data cache
- Or make sure that meta data items length match with the fields rendered
Comments
Comment #2
johnwebdev commentedComment #3
tedbowComment #6
wim leersI just:
first loaded
/node/1(an article node with tags)then manually deleted the
Drupal.quickedit.metadata.node/1/title/en/fullandDrupal.quickedit.metadata.node/1/field_tags/en/fullenabled JS debugger
then loaded
/node/1again, and observed it fetching the now-missing metadata prior to initializing Quick Edit for that entityWhich is also why the code looks like this:
Now how the initializing of the Quick Edit contextual link for an entity happens in a callback called by
fetchMissingMetadata()after it fetched the missing metadata :)Comment #7
wim leersThis is not async.
Comment #10
pameeela commented@johnwebdev do you think this is still an issue? If so would you be able to provide steps to reproduce?
Comment #11
johnwebdev commentedNo, I can't reproduce it anymore. Closing :) Thanks!
Comment #12
pameeela commentedGreat, thanks!