function uc_attribute_buy_it_now_form_validate in Ubercart 8.4
Validation callback for "buy it now" forms with attributes.
1 string reference to 'uc_attribute_buy_it_now_form_validate'
- uc_attribute_form_uc_product_buy_it_now_form_alter in uc_attribute/
uc_attribute.module - Implements hook_form_BASE_FORM_ID_alter() for uc_product_buy_it_now_form().
File
- uc_attribute/
uc_attribute.module, line 181 - Ubercart Attribute module.
Code
function uc_attribute_buy_it_now_form_validate(&$form, FormStateInterface $form_state) {
$attributes = uc_product_get_attributes($form_state
->getValue('nid'));
if (!empty($attributes)) {
\Drupal::messenger()
->addError(t('This product has options that need to be selected before purchase. Please select them in the form below.'));
$form_state
->setRedirect('entity.node.canonical', [
'node' => $form_state
->getValue('nid'),
]);
// Prevent submit handlers from running.
$form_state
->setSubmitHandlers([]);
}
}