You are here

public function CombinationOffer::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 PromotionOfferBase::validateConfigurationForm

File

modules/promotion/src/Plugin/Commerce/PromotionOffer/CombinationOffer.php, line 171

Class

CombinationOffer
Provides the 'combination_offer' offer plugin.

Namespace

Drupal\commerce_promotion\Plugin\Commerce\PromotionOffer

Code

public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
  $values = $form_state
    ->getValue($form['#parents']);

  // Filter out the button rows.
  $values['offers'] = array_filter($values['offers'], function ($offer) {
    return !empty($offer['target_plugin_id']) && !empty($offer['target_plugin_configuration']) && !isset($offer['add_offer']);
  });
  $form_state
    ->setValue($form['#parents'], $values);
  if (empty($values['offers'])) {
    $form_state
      ->setError($form['offers'], $this
      ->t('Please configure at least one offer.'));
  }
}