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!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ngocketit created an issue. See original summary.

ngocketit’s picture

Title: Quick Edit doesn't work for custom block » Quick Edit doesn't work for referenced custom block
Wim Leers’s picture

Category: Bug report » Support request
Status: Active » Postponed (maintainer needs more info)

Could you record & post a screencast demonstrating the problem? Thanks.

samuel.mortenson’s picture

Status: Postponed (maintainer needs more info) » Active

I'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

samuel.mortenson’s picture

Title: Quick Edit doesn't work for referenced custom block » Quick Edit doesn't work for Custom Blocks referenced by other Custom Blocks
Issue summary: View changes
Bcwald’s picture

I have confirmed this, I was able to replicate this issue.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Wim Leers’s picture

The 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.

Bcwald’s picture

The 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.

Wim Leers’s picture

Just reproduce the error with JS aggregation disabled, then look at the stack trace. You'll see where (in which JS) it was triggered.

Bcwald’s picture

drupal.js?v=8.1.0:67 Uncaught TypeError: Cannot read property 'getAttribute' of undefined
processField @ quickedit.js?v=8.1.0:380(anonymous function) @ quickedit.js?v=8.1.0:93
n.extend.each @ jquery.js:374
n.fn.n.each @ jquery.js:139
Drupal.behaviors.quickedit.attach @ quickedit.js?v=8.1.0:92
Drupal.attachBehaviors @ drupal.js?v=8.1.0:168
(anonymous function) @ drupal.js?v=8.1.0:178
n.addEventListener.t @ ready.min.js?v=1.0.8:4
Wim Leers’s picture

Category: Support request » Bug report

Ok, 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.

samuel.mortenson’s picture

I'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.

trwill’s picture

Had 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 :)

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

dkarso’s picture

Status: Postponed (maintainer needs more info) » Reviewed & tested by the community

#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.

Bcwald’s picture

I 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.

Wim Leers’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

This needs test coverage.

I intend to work on Quick Edit JS test coverage in the coming weeks.

Wim Leers’s picture

Title: Quick Edit doesn't work for Custom Blocks referenced by other Custom Blocks » [PP-1] Quick Edit doesn't work for Custom Blocks referenced by other Custom Blocks
Status: Needs work » Postponed
Related issues: +#2828528: Add Quick Edit Functional JS test coverage
Wim Leers’s picture

See #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.

Wim Leers’s picture

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Wim Leers’s picture

Title: [PP-1] Quick Edit doesn't work for Custom Blocks referenced by other Custom Blocks » Quick Edit doesn't work for Custom Blocks referenced by other Custom Blocks
Status: Postponed » Closed (duplicate)