You are here

protected function ProductVariationFieldRendererLayoutBuilder::renderLayoutBuilderFields in Commerce Core 8.2

Render fields from LayoutBuilder sections.

Parameters

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

\Drupal\layout_builder\Section[] $sections: The layout sections.

Return value

array Return array of rendered fields.

1 call to ProductVariationFieldRendererLayoutBuilder::renderLayoutBuilderFields()
ProductVariationFieldRendererLayoutBuilder::renderFields in modules/product/src/ProductVariationFieldRendererLayoutBuilder.php
Renders all renderable variation fields.

File

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

Class

ProductVariationFieldRendererLayoutBuilder

Namespace

Drupal\commerce_product

Code

protected function renderLayoutBuilderFields(ProductVariationInterface $variation, array $sections) {
  $build = [];

  // Loop trough sections, grab their components.
  foreach ($sections as $section) {

    // Grab section components, then loop trough them
    // to find fields from variations on each component.
    $components = $section
      ->getComponents();
    foreach ($components as $component) {
      $plugin = $component
        ->getPlugin();

      // We are only interested in field blocks from commerce product module.
      if ($plugin instanceof VariationFieldBlock) {
        $plugin_id = $plugin
          ->getPluginId();
        list(, , , $field_name) = explode(PluginBase::DERIVATIVE_SEPARATOR, $plugin_id, 4);
        $display_options = $plugin
          ->getConfiguration()['formatter'];

        // Render field with display options provided from plugin formatter.
        $build[$field_name] = $this
          ->prepareForAjax($this
          ->renderField($field_name, $variation, $display_options), $field_name, $variation);
      }
    }
  }
  return $build;
}