You are here

public function ProductSettingsForm::buildForm in Ubercart 8.4

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides ConfigFormBase::buildForm

File

uc_product/src/Form/ProductSettingsForm.php, line 60

Class

ProductSettingsForm
Configure product settings for this site.

Namespace

Drupal\uc_product\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('uc_product.settings');
  $form['product-settings'] = [
    '#type' => 'vertical_tabs',
  ];
  $form['product'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Product settings'),
    '#group' => 'product-settings',
    '#weight' => -10,
  ];
  $form['product']['empty'] = [
    '#markup' => $this
      ->t('There are currently no settings choices for your products. When enabled, the Cart module and other modules that provide product features (such as Role assignment and File downloads) will add settings choices here.'),
  ];
  $form['#submit'][] = [
    $this,
    'submitForm',
  ];
  if ($this->moduleHandler
    ->moduleExists('uc_cart')) {
    unset($form['product']['empty']);
    $form['product']['uc_product_add_to_cart_qty'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Display an optional quantity field in the <em>Add to Cart</em> form.'),
      '#default_value' => $config
        ->get('add_to_cart_qty'),
    ];
    $form['product']['uc_product_update_node_view'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Update product display based on customer selections'),
      '#default_value' => $config
        ->get('update_node_view'),
      '#description' => $this
        ->t('Check this box to dynamically update the display of product information such as display-price or weight based on customer input on the add-to-cart form (e.g. selecting a particular attribute option).'),
    ];
  }
  return parent::buildForm($form, $form_state);
}