You are here

public function ShipmentWeightMultipleConds::validateConfigurationForm in Commerce Shipping Weight Tariff 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/Commerce/Condition/ShipmentWeightMultipleConds.php \Drupal\commerce_shipping_weight_tariff\Plugin\Commerce\Condition\ShipmentWeightMultipleConds::validateConfigurationForm()

Validates filling of price and weight fields in enabled fieldsets.

Parameters

array $form: Configuration form array.

\Drupal\Core\Form\FormStateInterface $form_state: Form state object.

Overrides ConditionBase::validateConfigurationForm

File

src/Plugin/Commerce/Condition/ShipmentWeightMultipleConds.php, line 227

Class

ShipmentWeightMultipleConds
Provides the multiple weight condition for shipments.

Namespace

Drupal\commerce_shipping_weight_tariff\Plugin\Commerce\Condition

Code

public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
  parent::validateConfigurationForm($form, $form_state);
  $values = $form_state
    ->getValue($form['#parents']);
  for ($i = 1; $i <= 10; $i++) {
    $enabled = $values['condition_' . $i]['enabled'];
    $price = $values['condition_' . $i]['price'];
    $weight = $values['condition_' . $i]['weight'];
    if (empty($price['number']) && !empty($enabled)) {
      $element = $form['condition_' . $i]['price'];
      $form_state
        ->setError($element, 'You must enter correct price value!');
    }
    if (empty($weight['number']) && !empty($enabled)) {
      $element = $form['condition_' . $i]['weight'];
      $form_state
        ->setError($element, 'You must enter correct weight value!');
    }
  }
}