You are here

public function VariationXquantityStockSet::submitConfigurationForm in Commerce Extended Quantity 8

Form submission 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 PluginFormInterface::submitConfigurationForm

File

modules/xquantity_stock/src/Plugin/Action/VariationXquantityStockSet.php, line 86

Class

VariationXquantityStockSet
Set variation stock.

Namespace

Drupal\xquantity_stock\Plugin\Action

Code

public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
  if ($form_state
    ->getTriggeringElement()['#id'] != 'edit-cancel') {
    $values = $form_state
      ->getValues();
    $xquantity_stock = $form_state
      ->get('xquantity_stock');
    if (empty($xquantity_stock) || !is_numeric($value = $values['set_value'])) {
      \Drupal::messenger()
        ->AddError($this
        ->t('The inserted value is not numeric.'));
      return;
    }
    foreach ($form_state
      ->get('variations') as $variation) {
      $variation
        ->set($xquantity_stock, $value)
        ->save();
    }
  }
}