You are here

public function OrderFields::buildPaneSummary in Commerce Checkout Order Fields 8

Builds a summary of the pane values.

Important: The review pane shows summaries for both visible and non-visible panes. To skip showing a summary for a non-visible pane, check isVisible() and return an empty array.

Return value

array A render array containing the summary of the pane values.

Overrides CheckoutPaneBase::buildPaneSummary

File

src/Plugin/Commerce/CheckoutPane/OrderFields.php, line 128

Class

OrderFields
Exposes the "Checkout" form view mode during checkout.

Namespace

Drupal\commerce_checkout_order_fields\Plugin\Commerce\CheckoutPane

Code

public function buildPaneSummary() {
  $build = [];

  // Get the form display to discover which fields should be rendered for the
  // summary. View them using the same display mode ID as the form display
  // mode. If it exists, then Drupal will use it. If not, the default display
  // mode will be used.
  $view_builder = $this->entityTypeManager
    ->getViewBuilder('commerce_order');
  $form_display = $this
    ->getFormDisplay();
  foreach (array_keys($form_display
    ->getComponents()) as $component_name) {
    if (!$this->order
      ->get($component_name)
      ->isEmpty()) {
      $build[$component_name] = $view_builder
        ->viewField($this->order
        ->get($component_name), $this
        ->getDerivativeId());
    }
  }
  return $build;
}