You are here

protected function OrderItemMatcher::getCustomFields in Commerce Core 8.2

Gets the names of custom fields shown on the add to cart form.

Parameters

\Drupal\commerce_order\Entity\OrderItemInterface $order_item: The order item.

Return value

string[] The field names.

1 call to OrderItemMatcher::getCustomFields()
OrderItemMatcher::matchAll in modules/cart/src/OrderItemMatcher.php
Finds all matching order items for the given order item.

File

modules/cart/src/OrderItemMatcher.php, line 104

Class

OrderItemMatcher
Default implementation of the order item matcher.

Namespace

Drupal\commerce_cart

Code

protected function getCustomFields(OrderItemInterface $order_item) {
  $field_names = [];
  $storage = $this->entityTypeManager
    ->getStorage('entity_form_display');

  /** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $form_display */
  $form_display = $storage
    ->load('commerce_order_item.' . $order_item
    ->bundle() . '.' . 'add_to_cart');
  if ($form_display) {
    $field_names = array_keys($form_display
      ->getComponents());

    // Remove base fields.
    $field_names = array_diff($field_names, [
      'purchased_entity',
      'quantity',
      'created',
    ]);
  }
  return $field_names;
}