You are here

public function ProductVariationFieldRendererLayoutBuilder::renderFields in Commerce Core 8.2

Renders all renderable variation fields.

Parameters

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

string $view_mode: The view mode.

Return value

array Array of render arrays, keyed by field name.

Overrides ProductVariationFieldRenderer::renderFields

File

modules/product/src/ProductVariationFieldRendererLayoutBuilder.php, line 40

Class

ProductVariationFieldRendererLayoutBuilder

Namespace

Drupal\commerce_product

Code

public function renderFields(ProductVariationInterface $variation, $view_mode = 'default') {

  // Get parent product and load its view mode display.
  $product = $variation
    ->getProduct();
  assert($product !== NULL);
  $view_mode_display = $this->entityDisplayRepository
    ->getViewDisplay($product
    ->getEntityTypeId(), $product
    ->bundle(), $view_mode);

  // Check if layouts are enabled for that product.
  if ($view_mode_display instanceof LayoutBuilderEntityViewDisplay && $view_mode_display
    ->isLayoutBuilderEnabled()) {

    // Grab sections from bundle layout view mode.
    $sections = $view_mode_display
      ->getSections();

    // If overrides are allowed, fetch them if they exists.
    if ($view_mode_display
      ->isOverridable() && ($overrides = $this
      ->getEntitySections($variation
      ->getProduct()))) {
      $sections = $overrides;
    }

    // Render fields for output.
    return $this
      ->renderLayoutBuilderFields($variation, $sections);
  }

  // If no layouts are enabled proceed to regular rendering.
  return parent::renderFields($variation, $view_mode);
}