You are here

public function ProductVariationFieldRenderer::renderField in Commerce Core 8.2

Renders a single variation field.

Parameters

string $field_name: The field name.

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

string|array $display_options: Can be either:

  • The name of a view mode. The field will be displayed according to the display settings specified for this view mode in the $field definition for the field in the entity's bundle. If no display settings are found for the view mode, the settings for the 'default' view mode will be used.
  • An array of display options. The following key/value pairs are allowed:
    • label: (string) Position of the label. The default 'field' theme implementation supports the values 'inline', 'above' and 'hidden'. Defaults to 'above'.
    • type: (string) The formatter to use. Defaults to the 'default_formatter' for the field type. The default formatter will also be used if the requested formatter is not available.
    • settings: (array) Settings specific to the formatter. Defaults to the formatter's default settings.
    • weight: (float) The weight to assign to the renderable element. Defaults to 0.

Return value

array The render array.

Overrides ProductVariationFieldRendererInterface::renderField

1 call to ProductVariationFieldRenderer::renderField()
ProductVariationFieldRendererLayoutBuilder::renderLayoutBuilderFields in modules/product/src/ProductVariationFieldRendererLayoutBuilder.php
Render fields from LayoutBuilder sections.

File

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

Class

ProductVariationFieldRenderer

Namespace

Drupal\commerce_product

Code

public function renderField($field_name, ProductVariationInterface $variation, $display_options = []) {
  $rendered_field = $this->variationViewBuilder
    ->viewField($variation
    ->get($field_name), $display_options);

  // An empty array indicates that the field is hidden on the view display.
  if (!empty($rendered_field)) {
    $rendered_field = $this
      ->prepareForAjax($rendered_field, $field_name, $variation);
  }
  return $rendered_field;
}