Problem/Motivation

When rendering injected field from the commerce variation entity into the commerce product template, we’ve got warning in the console about Quick Edit

Quick Edit could not associate the rendered entity field markup (with [data-quickedit-field-id="commerce_product_variation/4361/price/fr/full"]) with the corresponding rendered entity markup: no parent DOM node found with [data-quickedit-entity-id="commerce_product_variation/4361"]. This is typically caused by the theme's template for this entity type forgetting to print the attributes.

For example, the price field is rendered from the commerce_product.html.twig template as below

{# Sidebar #}
<div class="product-sidebar col-xs-12 col-sm-4 col-md-3 pull-right">
  {{ product.variation_price }}
</div>

This error make sens as the fields are not rendered into the commerce_product_variation template, and so Quick edit didn't find the corresponding data-quickedit-entity-id for the commerce product variation

Proposed resolution

Add a wrapper around the field injected width the data-quickedit-entity-id ? But then we could have several and similar data-quickedit-entity-id attributes in the DOM.

Don't support the quick edit feature on theses fields injected into the commerce product template ? And so remove this attribute for any field injected ?

It seems that injected field is a scenario not supported by Quick Edit module (because injected field are not rendered in their entity's view mode)

In quickedit module we can read line 140

  // Quick Edit module only supports view modes, not dynamically defined
  // "display options" (which \Drupal\Core\Field\FieldItemListInterface::view()
  // always names the "_custom" view mode).
  // @see \Drupal\Core\Field\FieldItemListInterface::view()
  // @see https://www.drupal.org/node/2120335
  if ($element['#view_mode'] === '_custom') {
    return;
  }

So, we could prevent Quick edit to add its attributes on the injected fields

Remaining tasks

- Create a patch

User interface changes

None

API changes

None

Data model changes

None

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

flocondetoile created an issue. See original summary.

flocondetoile’s picture

Issue summary: View changes
flocondetoile’s picture

It seems that injected field is a scenario not supported by Quick Edit module (because injected field are not rendered in their entity's view mode)

In quickedit module we can read line 140

  // Quick Edit module only supports view modes, not dynamically defined
  // "display options" (which \Drupal\Core\Field\FieldItemListInterface::view()
  // always names the "_custom" view mode).
  // @see \Drupal\Core\Field\FieldItemListInterface::view()
  // @see https://www.drupal.org/node/2120335
  if ($element['#view_mode'] === '_custom') {
    return;
  }

Overriding the $rendered_field #view_mode property into the ProductViewBuilder::afterBuild() method could be a workaround.

Computed field are excluded too from the quick edit preprocess function which add this attribute. Could we consider these injected field as computed ?

flocondetoile’s picture

Status: Active » Needs review
FileSize
1.74 KB

First attempt. Choose to override the $rendered_field #view_mode property into the ProductViewBuilder::afterBuild() method to prevent quick edit to add its attributes on the injected fields.

Status: Needs review » Needs work

The last submitted patch, 4: 2923337-4.patch, failed testing. View results

flocondetoile’s picture

Status: Needs work » Needs review

Fail is unrelated. Setting back to NR.

flocondetoile’s picture

Issue summary: View changes
FileSize
1.74 KB

rerolled #4

flocondetoile’s picture

Issue summary: View changes

  • bojanz committed 4691303 on 8.x-2.x authored by flocondetoile
    Issue #2923337 by flocondetoile: Quick edit error when rendering...
bojanz’s picture

Status: Needs review » Fixed

Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

krystalcode’s picture

Is there a better solution for this problem? Setting the view mode to '_custom' creates theming problems. For example we cannot render the price differently based on the variation view mode by choosing a different field template.

bojanz’s picture

Status: Closed (fixed) » Needs work

Reopening cause of the theming regression.

An alternative would be to get our preprocess hook to run after quickedit_preprocess_field(), and then to unset the data-quickedit-field-id attribute for each injected field.

  • bojanz committed a06dd01 on 8.x-2.x
    Issue #2923337 followup: Fix regression that broke theme suggestions for...
bojanz’s picture

Status: Needs work » Fixed

Done. Apologies for the regression.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

japo32’s picture

Hi,

I'm still seeing the error so I checked and it looks like the #ajax_replace_class item is inside the element item.

japo32’s picture

sorry, here's the correctly formatted patch.

japo32’s picture

bojanz’s picture

Status: Closed (fixed) » Needs work

Checking.

  • bojanz committed b905adc on 8.x-2.x authored by japo32
    Issue #2923337 by flocondetoile, japo32, bojanz: Quick edit error when...
bojanz’s picture

Status: Needs work » Fixed

I guess third time's the charm. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

ishmelev’s picture

Uncaught Error: Quick Edit could not associate the rendered entity field markup (with [data-quickedit-field-id="commerce_product_variation/31/price/ru/full"]) with the corresponding rendered entity markup: no parent DOM node found with [data-quickedit-entity-id="commerce_product_variation/31"]. This is typically caused by the theme's template for this entity type forgetting to print the attributes.
at processField (quickedit.js?v=8.8.6:181)
PHP - 7.2.30
Drupal - 8.8.6

robcarr’s picture

I'm seeing a similar error to that reported at #24.

The patch at #18 is implemented in current production release of Commerce 8.x-2.23

I'd say this problem wasn't wholly addressed by this issue.