public function CommerceCartRedirectionConfigForm::buildForm in Commerce Cart Redirection 8.2
Same name and namespace in other branches
- 3.0.x src/Form/CommerceCartRedirectionConfigForm.php \Drupal\commerce_cart_redirection\Form\CommerceCartRedirectionConfigForm::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/ CommerceCartRedirectionConfigForm.php, line 86
Class
- CommerceCartRedirectionConfigForm
- Class CommerceCartRedirectionConfigForm.
Namespace
Drupal\commerce_cart_redirection\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
// @NOTE due to an error in using commerce_product bundles in place of
// commerce_product_variation bundles the config values are now misnamed
// and should be fixed to be product_variation_bundles etc at some point.
// Load all bundle types for commerce_product_variation.
// @TODO This means the redirect won't work for entities that implement
// purchasable but aren't commerce_product_variation(s) Fix?
$config = $this
->config('commerce_cart_redirection.settings');
$bundle_options = [];
$bundles = $this->entityTypeBundleInfo
->getBundleInfo('commerce_product_variation');
foreach ($bundles as $key => $bundle) {
$bundle_options[$key] = $bundle['label'];
}
$form['product_bundles'] = [
'#type' => 'checkboxes',
'#title' => $this
->t('Product Variation Bundles'),
'#description' => $this
->t('Select the product variation bundles you want to redirect to Checkout on Add To Cart'),
'#weight' => '0',
'#options' => $bundle_options,
'#default_value' => $config
->get('product_bundles'),
];
$form['negate_product_bundles'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Negate the Bundles condition'),
'#default_value' => $config
->get('negate_product_bundles'),
'#weight' => '0',
];
$path_options = [
'checkout' => 'Checkout',
'cart' => 'Cart',
'other' => 'Other',
];
$form['redirection_route_path'] = [
'#type' => 'radios',
'#title' => $this
->t('Select the redirection route'),
'#weight' => '10',
'#options' => $path_options,
'#default_value' => $config
->get('redirection_route_path'),
];
$form['redirection_route_path_other'] = [
'#type' => 'textfield',
'#description' => $this
->t('You can enter any url, local or remote. When entering your own you need to ensure it is valid & safe, there is no checking done by this module.'),
'#weight' => '15',
'#default_value' => $config
->get('redirection_route_path_other'),
'#states' => [
'visible' => [
'[name="redirection_route_path"]' => [
'value' => 'other',
],
],
'required' => [
'[name="redirection_route_path"]' => [
'value' => 'other',
],
],
],
];
$form['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Submit'),
'#weight' => '100',
];
return $form;
}