Problem/Motivation
When rendering Custom Blocks (with fields) inside Custom Blocks using an Entity Reference field, Quickedit throws errors and does not work on the nested Custom Blocks.
Replication steps:
1) Visit /admin/structure/block/block-content/manage/basic/fields/add-field
2) Add a Reference > Other field, move on to the next screen, then reference Content Blocks. Continue through the form using default settings.
3) Visit /admin/structure/block/block-content/manage/basic/display, change format for your new field to to "Rendered entity"
4) Create a block at /block/add/basic, fill in the Title and Body fields
5) Don't place this block in a region (it will be out nested block)
6) Create another block at /block/add/basic, fill in the Title and Body fields, and in your Entity Reference field reference the block created in step (4)
7) Place this block in a visible region
8) Visit any page that renders that block
9) See that in the browser console, the error "Uncaught TypeError: Cannot read property 'getAttribute' of undefined" is thrown
Proposed resolution
None yet.
Remaining tasks
Replicate issue steps and determine if this is a distinct issue from #2666578: Block Content entities have no Contextual links when rendered outside of Block config entity.
Original report byngocketit
Hi,
I have an entity reference field that is set to reference a custom block and formatted as "Rendered entity". However, when the parent node renders, the Quick Edit contextual menu doesn't show up for the block. Is it an error or purposely done?
Thanks!
Comment | File | Size | Author |
---|---|---|---|
#14 | quickedit-undefined-attr-2661880-14.patch | 1.09 KB | trwill |
#13 | Missing wrapping element.png | 202.13 KB | samuel.mortenson |
#13 | Debugging at point which error is thrown.png | 107.7 KB | samuel.mortenson |
Comments
Comment #2
ngocketit CreditAttribution: ngocketit commentedComment #3
Wim LeersCould you record & post a screencast demonstrating the problem? Thanks.
Comment #4
samuel.mortensonI'm seeing this in Entity Reference fields on Content/Content Blocks. Replication steps for this issue (from stock Drupal 8 install):
1) Visit /admin/structure/block/block-content/manage/basic/fields/add-field
2) Add a Reference > Other field, move on to the next screen, then reference Content Blocks. Continue through the form using default settings.
3) Visit /admin/structure/block/block-content/manage/basic/display, change format for your new field to to "Rendered entity"
4) Create a block at /block/add/basic, fill in the Title and Body fields
5) Don't place this block in a region (it will be out nested block)
6) Create another block at /block/add/basic, fill in the Title and Body fields, and in your Entity Reference field reference the block created in step (4)
7) Place this block in a visible region
8) Visit any page that renders that block
9) See that in the browser console, the error "Uncaught TypeError: Cannot read property 'getAttribute' of undefined" is thrown
Possibly related issues: #2658270: BlockViewBuilder::preRender() must not mess with block render arrays / #2666578: Block Content entities have no Contextual links when rendered outside of Block config entity
Comment #5
samuel.mortensonComment #6
Bcwald CreditAttribution: Bcwald commentedI have confirmed this, I was able to replicate this issue.
Comment #8
Wim LeersThe STR are there, which is great. But there's nothing there yet about the JS error. Which JS file is throwing that error? Are you sure it's not Contextual Links?
This seems somewhat related to #2551373: contextual.js and quickedit.js should fail gracefully, with useful error messages, when Twig templates forget to print attributes.
Comment #9
Bcwald CreditAttribution: Bcwald commentedThe error is not very helpful, would need to backtrace
drupal.js?v=8.1.0:67 Uncaught TypeError: Cannot read property 'getAttribute' of undefined
Perhaps @mortenson can provide moe information here.
Comment #10
Wim LeersJust reproduce the error with JS aggregation disabled, then look at the stack trace. You'll see where (in which JS) it was triggered.
Comment #11
Bcwald CreditAttribution: Bcwald commentedComment #12
Wim LeersOk, so it's happening in the
processField()
function. Putting a breakpoint in there would allow you to see which HTML expectations Quick Edit has that are not being met.Comment #13
samuel.mortensonI've uploaded some screenshots which show the debugging process - basically it looks like there is no [data-quickedit-entity-id] wrapping element for child Custom Blocks, which as noted in the original issue summary could be related to #2666578: Block Content entities have no Contextual links when rendered outside of Block config entity. Also verified that the original STR are still valid in 8.1.0.
Not changing the issue status in case more information is needed.
Comment #14
trwill CreditAttribution: trwill commentedHad the same issue, a check to see if entityElement.get(0) is defined seems to fix it. Please be gentle - this is my first core patch :)
Comment #16
dkarso CreditAttribution: dkarso as a volunteer commented#14 Corrects the error and I am capable of editing the custom block in the custom block. The other fields are also still editable.
I think this patch should be added to make quickedit.js more robust. The related issue https://www.drupal.org/node/2666578 should also help fix this but quickedit.js needs more value checking. It is too fragile.
Comment #17
Bcwald CreditAttribution: Bcwald commentedI guess I missed this patch showing up, but just saw it now. I tested it out and it seems to work good in my situation.
Comment #18
Wim LeersThis needs test coverage.
I intend to work on Quick Edit JS test coverage in the coming weeks.
Comment #19
Wim LeersPostponing on #2828528: Add Quick Edit Functional JS test coverage.
Comment #20
Wim LeersSee #2828528-26: Add Quick Edit Functional JS test coverage, that now has explicit test coverage for starting the in-place editing of custom blocks.
#14 looks like a work-around, not a fix. AFAICT it will just ignore every field for a nested entity, whereas we need logic (and test coverage) to explicitly deal with that.
Comment #21
Wim LeersAlso, #14 has a fix that is functionally identical to the patch for #2314185: [PP-1] DrupalBehaviorError: attach ; quickedit: entityElement.get(...) is undefined.
Comment #24
Wim LeersAFAICT this was fixed in #2551373: contextual.js and quickedit.js should fail gracefully, with useful error messages, when Twig templates forget to print attributes.