You are here

public function XquantityOrderItem::getQuantityWidgetSettings in Commerce Extended Quantity 8

2 calls to XquantityOrderItem::getQuantityWidgetSettings()
XquantityOrderItem::getItemsQuantity in src/Entity/XquantityOrderItem.php
XquantityOrderItem::setQuantityPrices in src/Entity/XquantityOrderItem.php

File

src/Entity/XquantityOrderItem.php, line 68

Class

XquantityOrderItem
Overrides the order item entity class.

Namespace

Drupal\commerce_xquantity\Entity

Code

public function getQuantityWidgetSettings() {
  $settings = [];
  $settings['disable_on_cart'] = FALSE;

  // If 'Add to cart' form display mode is enabled we prefer its settings
  // because exactly those settings are exposed to and used by a customer.
  $form_display = $this
    ->getFormDisplayWidget();
  $quantity = $form_display ? $form_display
    ->getComponent('quantity') : NULL;
  if (!$quantity) {
    $form_display = $this
      ->getFormDisplayWidget('default');
    $quantity = $form_display ? $form_display
      ->getComponent('quantity') : NULL;
  }
  if (isset($quantity['settings']['step'])) {
    $settings = $form_display
      ->getRenderer('quantity')
      ->getFormDisplayModeSettings();
  }
  else {

    // Fallback if 'default' or 'add_to_cart' form modes don't exist.
    $settings += (array) $this
      ->get('quantity')
      ->getSettings();
  }
  return $settings;
}