You are here

function commerce_file_product_variation_type_form_validate in Commerce File 8.2

Validation handler for commerce_file_form_commerce_product_variation_type_form_alter().

1 string reference to 'commerce_file_product_variation_type_form_validate'
commerce_file_form_commerce_product_variation_type_form_alter in ./commerce_file.module
Implements hook_form_BASE_FORM_ID_alter().

File

./commerce_file.module, line 156
Extends Commerce License with the ability to sell access to files.

Code

function commerce_file_product_variation_type_form_validate(array &$form, FormStateInterface $form_state) {

  // Automatically select the license trait if the file trait is selected.
  $traits = $form_state
    ->getValue('traits');
  $original_traits = $form_state
    ->getValue('original_traits');
  if ($traits['commerce_file'] !== 0) {
    if (empty($traits['commerce_license']) && !in_array('commerce_license', $original_traits)) {
      $form_state
        ->setValue('license_trait_auto_configured', TRUE);
      $form_state
        ->setValue([
        'traits',
        'commerce_license',
      ], 'commerce_license');
      $form_state
        ->setValue('license_types', [
        'commerce_file' => 'commerce_file',
      ]);
    }
  }
}