You are here

public function CartSettingsForm::buildForm in Basic cart 8.4

Same name and namespace in other branches
  1. 8.6 src/Form/CartSettingsForm.php \Drupal\basic_cart\Form\CartSettingsForm::buildForm()
  2. 8 src/Form/CartSettingsForm.php \Drupal\basic_cart\Form\CartSettingsForm::buildForm()
  3. 8.0 src/Form/CartSettingsForm.php \Drupal\basic_cart\Form\CartSettingsForm::buildForm()
  4. 8.2 src/Form/CartSettingsForm.php \Drupal\basic_cart\Form\CartSettingsForm::buildForm()
  5. 8.3 src/Form/CartSettingsForm.php \Drupal\basic_cart\Form\CartSettingsForm::buildForm()
  6. 8.5 src/Form/CartSettingsForm.php \Drupal\basic_cart\Form\CartSettingsForm::buildForm()

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

src/Form/CartSettingsForm.php, line 33

Class

CartSettingsForm
Configure basic_cart settings for this site.

Namespace

Drupal\basic_cart\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('basic_cart.settings');
  $node_types = node_type_get_types();
  if (empty($node_types)) {
    return NULL;
  }
  $options = array();
  foreach ($node_types as $node_type => $type) {
    if ($node_type == 'basic_cart_order' || $node_type == 'basic_cart_connect') {
      continue;
    }
    $options[$node_type] = $type
      ->get('name');
  }
  $form['content_type'] = array(
    '#title' => t('Content type selection'),
    '#type' => 'fieldset',
    '#description' => t('Please select the content types for which you wish to have the "Add to cart" option.'),
  );
  $form['content_type']['basic_cart_content_types'] = array(
    '#title' => t('Content types'),
    '#type' => 'checkboxes',
    '#options' => $options,
    '#default_value' => $config
      ->get('content_type'),
  );
  $form['content_type']['basic_cart_all_content_types'] = array(
    '#type' => 'hidden',
    '#default_value' => $config
      ->get('content_type'),
  );
  $form['table'] = array(
    '#title' => t('Store cart data in database table'),
    '#type' => 'fieldset',
    '#description' => t('Enable cart to store the data in database instead of session. Data will persist only when user logged in'),
  );
  $form['table']['basic_cart_use_cart_table'] = array(
    '#title' => t('Persist cart data'),
    '#type' => 'checkbox',
    '#description' => t('This option will enable to persist cart data even the user is logged out and logging in again'),
    '#default_value' => $config
      ->get('use_cart_table'),
  );
  $form['currency'] = array(
    '#title' => t('Currency and price'),
    '#type' => 'fieldset',
    '#description' => t('Please select the currency in which the prices will be calculated.'),
  );
  $form['currency']['basic_cart_currency_status'] = array(
    '#title' => t('Enable Currency'),
    '#type' => 'checkbox',
    '#description' => t('Enable Currency for your cart price,this will available only if price is enabled'),
    '#default_value' => $config
      ->get('currency_status'),
  );
  $form['currency']['basic_cart_currency'] = array(
    '#title' => t('Currency'),
    '#type' => 'textfield',
    '#description' => t("Please choose the currency."),
    '#default_value' => $config
      ->get('currency'),
  );
  $form['currency']['basic_cart_price_format'] = array(
    '#title' => t('Price format'),
    '#type' => 'select',
    '#options' => Utility::listPriceFormats(),
    '#description' => t("Please choose the format in which the price will be shown."),
    '#default_value' => $config
      ->get('price_format'),
  );
  $form['currency']['basic_cart_quantity_status'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Enable quantity'),
    '#default_value' => $config
      ->get('quantity_status'),
    '#description' => t('Enable quantity  for your cart, if quantity not enabled you can add to a cart without quantity'),
  );
  $form['currency']['basic_cart_price_status'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Enable price'),
    '#default_value' => $config
      ->get('price_status'),
    '#description' => t('Enable price for your cart, if price not enabled you can add to a cart without price'),
  );
  $form['currency']['basic_cart_total_price_status'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Enable total price'),
    '#default_value' => $config
      ->get('total_price_status'),
    '#description' => t('Enable total price for your cart, if total price is not enabled your cart would not have total price calcutaion'),
  );
  $form['vat'] = array(
    '#title' => t('VAT'),
    '#type' => 'fieldset',
  );
  $form['vat']['basic_cart_vat_state'] = array(
    '#title' => t('Check if you want to apply the VAT tax on the total amount in the checkout process.'),
    '#type' => 'checkbox',
    '#default_value' => $config
      ->get('vat_state'),
  );
  $form['vat']['basic_cart_vat_value'] = array(
    '#title' => t('VAT value'),
    '#type' => 'textfield',
    '#description' => t("Please enter VAT value."),
    '#field_suffix' => '%',
    '#size' => 10,
    '#default_value' => $config
      ->get('vat_value'),
  );
  $form['order'] = array(
    '#title' => t('Basic Cart Order'),
    '#type' => 'fieldset',
  );
  $form['order']['basic_cart_order_status'] = array(
    '#title' => t('Check if you want to create order for the cart.'),
    '#type' => 'checkbox',
    '#default_value' => $config
      ->get('order_status'),
  );
  $form['redirect'] = array(
    '#title' => t('Redirect user after adding an item to the shopping cart'),
    '#type' => 'fieldset',
  );
  $form['redirect']['basic_cart_add_to_cart_redirect'] = array(
    '#title' => t('Add to cart redirect'),
    '#type' => 'textfield',
    '#description' => t("Enter the page you wish to redirect the customer to when an item is added to the cart, or <none> for no redirect."),
    '#default_value' => $config
      ->get('add_to_cart_redirect'),
  );
  $form['configure'] = array(
    '#title' => t('Configure texts'),
    '#type' => 'fieldset',
  );
  $form['configure']['basic_cart_cart_page_title'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Page title'),
    '#default_value' => $config
      ->get('cart_page_title'),
    '#description' => t('Please configure page title to be shown in your cart page'),
  );
  $form['configure']['basic_cart_empty_cart'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Empty Cart'),
    '#default_value' => $config
      ->get('empty_cart'),
    '#description' => t('Please configure a text when your cart is empty'),
  );
  $form['configure']['basic_cart_cart_block_title'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Block Title'),
    '#default_value' => $config
      ->get('cart_block_title'),
    '#description' => t('Please configure your cart block title'),
  );
  $form['configure']['basic_cart_view_cart_button'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('View cart'),
    '#default_value' => $config
      ->get('view_cart_button'),
    '#description' => t('Please configure your text on view cart button'),
  );
  $form['configure']['basic_cart_cart_update_button'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Update cart button'),
    '#default_value' => $config
      ->get('cart_update_button'),
    '#description' => t('Please configure your text on update cart button'),
  );
  $form['configure']['basic_cart_cart_updated_message'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Cart updated message'),
    '#default_value' => $config
      ->get('cart_updated_message'),
    '#description' => t('Please configure message to show after the cart updated'),
  );
  $form['configure']['basic_cart_quantity_label'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Quantity label'),
    '#default_value' => $config
      ->get('quantity_label'),
    '#description' => t('Please configure your text for quantity label,this will available only if quantity is enabled'),
  );
  $form['configure']['basic_cart_price_label'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Price label'),
    '#default_value' => $config
      ->get('price_label'),
    '#description' => t('Please configure your text for price label,this will available only if price is enabled'),
  );
  $form['configure']['basic_cart_total_price_label'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Total price label'),
    '#default_value' => $config
      ->get('total_price_label'),
    '#description' => t('Please configure your text for total price label,this will available only if total price is enabled'),
  );
  $form['configure']['basic_cart_add_to_cart_button'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Add to Cart'),
    '#default_value' => $config
      ->get('add_to_cart_button'),
    '#description' => t('Please configure your text on update cart button'),
  );
  $form['configure']['basic_cart_added_to_cart_message'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Added to Cart'),
    '#default_value' => $config
      ->get('added_to_cart_message'),
    '#description' => t('Please configure your text on to appear after the entity is added to cart'),
  );
  return parent::buildForm($form, $form_state);
}