Skip to content
Snippets Groups Projects
Commit 18ddf4e9 authored by Jonathan Sacksick's avatar Jonathan Sacksick
Browse files

Revert "Issue #3120117 by Neograph734: ProductVariationFieldRenderer's...

Revert "Issue #3120117 by Neograph734: ProductVariationFieldRenderer's AJAXifiying breaks lazy_built fields (such as flags)."

This reverts commit 666eaa01.
parent ff5d6680
No related branches found
Tags 7.x-1.3
No related merge requests found
......@@ -91,16 +91,15 @@ class ProductVariationFieldRenderer implements ProductVariationFieldRendererInte
*/
protected function prepareForAjax(array $rendered_field, $field_name, ProductVariationInterface $variation) {
$ajax_class = $this->buildAjaxReplacementClass($field_name, $variation);
$rendered_field['#attributes']['class'][] = $ajax_class;
$rendered_field['#ajax_replace_class'] = $ajax_class;
// Ensure that a <div> is rendered even if the field is empty, to allow
// field replacement to work when the variation changes.
if (!Element::children($rendered_field)) {
$rendered_field['#type'] = 'container';
}
// Add a wrapper for the AJAX replacement. Do not tamper with the original
// render array because fields with a #lazy_builder property cannot have an
// #attributes property as well.
return [
'#type' => 'container',
'#attributes' => ['class' => [$ajax_class]],
'#ajax_replace_class' => $ajax_class,
'rendered_field' => $rendered_field,
];
return $rendered_field;
}
/**
......
......@@ -167,9 +167,9 @@ class ProductVariationFieldRendererTest extends CommerceKernelTestBase {
$this->assertArrayHasKey('sku', $rendered_fields);
$this->assertArrayHasKey('attribute_color', $rendered_fields);
$this->assertNotEmpty($rendered_fields['sku']);
$this->assertNotEmpty($rendered_fields['sku']['rendered_field'][0]);
$this->assertNotEmpty($rendered_fields['sku'][0]);
$this->assertNotEmpty($rendered_fields['attribute_color']);
$this->assertNotEmpty($rendered_fields['attribute_color']['rendered_field'][0]);
$this->assertNotEmpty($rendered_fields['attribute_color'][0]);
$this->assertEquals('product--variation-field--variation_sku__' . $variation->getProductId(), $rendered_fields['sku']['#ajax_replace_class']);
$this->assertEquals('product--variation-field--variation_attribute_color__' . $variation->getProductId(), $rendered_fields['attribute_color']['#ajax_replace_class']);
// Confirm that an empty field gets a rendered wrapper.
......@@ -316,7 +316,7 @@ class ProductVariationFieldRendererTest extends CommerceKernelTestBase {
$rendered_field = $this->variationFieldRenderer->renderField('sku', $variation, 'default');
$this->assertNotEmpty($rendered_field);
$this->assertNotEmpty($rendered_field['rendered_field'][0]);
$this->assertNotEmpty($rendered_field[0]);
$this->assertEquals('product--variation-field--variation_sku__' . $variation->getProductId(), $rendered_field['#ajax_replace_class']);
// Confirm that an empty field gets a rendered wrapper.
......@@ -334,7 +334,7 @@ class ProductVariationFieldRendererTest extends CommerceKernelTestBase {
'type' => 'commerce_price_default',
]);
$this->assertNotEmpty($rendered_field);
$this->assertNotEmpty($rendered_field['rendered_field'][0]);
$this->assertNotEmpty($rendered_field[0]);
$this->assertEquals('product--variation-field--variation_price__' . $variation->getProductId(), $rendered_field['#ajax_replace_class']);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment