You are here

protected function ProductVariationFieldRenderer::prepareForAjax in Commerce Core 8.2

Prepares the rendered field for AJAX replacement.

Parameters

array $rendered_field: The rendered field.

string $field_name: The field name.

\Drupal\commerce_product\Entity\ProductVariationInterface $variation: The product variation.

Return value

array The prepared rendered field.

3 calls to ProductVariationFieldRenderer::prepareForAjax()
ProductVariationFieldRenderer::renderField in modules/product/src/ProductVariationFieldRenderer.php
Renders a single variation field.
ProductVariationFieldRenderer::renderFields in modules/product/src/ProductVariationFieldRenderer.php
Renders all renderable variation fields.
ProductVariationFieldRendererLayoutBuilder::renderLayoutBuilderFields in modules/product/src/ProductVariationFieldRendererLayoutBuilder.php
Render fields from LayoutBuilder sections.

File

modules/product/src/ProductVariationFieldRenderer.php, line 92

Class

ProductVariationFieldRenderer

Namespace

Drupal\commerce_product

Code

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';
  }
  return $rendered_field;
}