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
Comment | File | Size | Author |
---|---|---|---|
#18 | quick_edit_error-2923337-18.patch | 663 bytes | japo32 |
#7 | 2923337-7.patch | 1.74 KB | flocondetoile |
| |||
#4 | 2923337-4.patch | 1.74 KB | flocondetoile |
Comments
Comment #2
flocondetoileComment #3
flocondetoileIt 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
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 ?
Comment #4
flocondetoileFirst 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.
Comment #6
flocondetoileFail is unrelated. Setting back to NR.
Comment #7
flocondetoilererolled #4
Comment #8
flocondetoileComment #10
bojanz CreditAttribution: bojanz at Centarro commentedThanks!
Comment #12
krystalcode CreditAttribution: krystalcode at Acro Commerce commentedIs 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.
Comment #13
bojanz CreditAttribution: bojanz at Centarro commentedReopening 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.
Comment #15
bojanz CreditAttribution: bojanz at Centarro commentedDone. Apologies for the regression.
Comment #17
japo32 CreditAttribution: japo32 at Catalyst IT commentedHi,
I'm still seeing the error so I checked and it looks like the
#ajax_replace_class
item is inside theelement
item.Comment #18
japo32 CreditAttribution: japo32 at Catalyst IT commentedsorry, here's the correctly formatted patch.
Comment #19
japo32 CreditAttribution: japo32 at Catalyst IT commentedComment #20
bojanz CreditAttribution: bojanz at Centarro commentedChecking.
Comment #22
bojanz CreditAttribution: bojanz at Centarro commentedI guess third time's the charm. Thanks!
Comment #24
ishmelev CreditAttribution: ishmelev commentedUncaught 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
Comment #25
robcarrI'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.