You are here

function uc_ups_form_node_form_alter in Ubercart 8.4

Implements hook_form_BASE_FORM_ID_alter() for node_form().

Adds package type to products.

See also

uc_product_form()

uc_ups_product_alter_validate()

File

shipping/uc_ups/uc_ups.module, line 95
UPS shipping quote module.

Code

function uc_ups_form_node_form_alter(&$form, FormStateInterface $form_state) {
  $ups_config = \Drupal::config('uc_ups.settings');
  $quote_config = \Drupal::config('uc_quote.settings');
  $node = $form_state
    ->getFormObject()
    ->getEntity();
  if (uc_product_is_product($node
    ->bundle())) {
    $enabled = $quote_config
      ->get('enabled') + [
      'ups' => FALSE,
    ];
    $weight = $quote_config
      ->get('method_weight') + [
      'ups' => 0,
    ];
    $ups = [
      '#type' => 'details',
      '#title' => t('UPS product description'),
      '#weight' => $weight['ups'],
      '#tree' => TRUE,
    ];
    $ups['pkg_type'] = [
      '#type' => 'select',
      '#title' => t('Package type'),
      '#options' => UPSUtilities::packageTypes(),
      '#default_value' => isset($node->ups['pkg_type']) ? $node->ups['pkg_type'] : $ups_config
        ->get('pkg_type'),
    ];
    $form['shipping']['ups'] = $ups;
    if ($enabled['ups']) {
      $form['#validate'][] = 'uc_ups_product_alter_validate';
    }
  }
}