public function Custom::validateConfigurationForm in Commerce Core 8.2
Form validation handler.
Parameters
array $form: An associative array containing the structure of the plugin form as built by static::buildConfigurationForm().
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().
Overrides TaxTypeBase::validateConfigurationForm
File
- modules/
tax/ src/ Plugin/ Commerce/ TaxType/ Custom.php, line 290
Class
- Custom
- Provides the Custom tax type.
Namespace
Drupal\commerce_tax\Plugin\Commerce\TaxTypeCode
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
$values = $form_state
->getValue($form['#parents']);
// Filter out the button rows.
$values['rates'] = array_filter($values['rates'], function ($rate) {
return !empty($rate) && !isset($rate['add_rate']);
});
$values['territories'] = array_filter($values['territories'], function ($territory) {
return !empty($territory) && !isset($territory['add_territory']);
});
$form_state
->setValue($form['#parents'], $values);
if (empty($values['rates'])) {
$form_state
->setError($form['rates'], $this
->t('Please add at least one rate.'));
}
if (empty($values['territories'])) {
$form_state
->setError($form['territories'], $this
->t('Please add at least one territory.'));
}
}