public function VariationDuplicate::submitConfigurationForm in Commerce Bulk 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
- src/
Plugin/ Action/ VariationDuplicate.php, line 120
Class
- VariationDuplicate
- Duplicate variation.
Namespace
Drupal\commerce_bulk\Plugin\ActionCode
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
if ($form_state
->getTriggeringElement()['#id'] != 'edit-cancel') {
if (($kit = $form_state
->get('kit')) && $kit['all']['not_used_combinations']) {
$values = $form_state
->getValues();
if ($values['max_execution_time']) {
ini_set('max_execution_time', $values['max_execution_time']);
}
$attributes = [];
foreach (array_keys($kit['options']['options']) as $key) {
$attributes[$key] = $values[$key];
}
foreach ($kit['all']['not_used_combinations'] as $index => $combination) {
foreach ($combination as $key => $value) {
if (!isset($attributes[$key][$value])) {
unset($kit['all']['not_used_combinations'][$index]);
continue 2;
}
}
}
$count = count($kit['all']['not_used_combinations']);
if ($count > 100) {
$count = 0;
$all = [];
$all['all']['last_variation'] = $kit['all']['last_variation'];
foreach ($kit['all']['not_used_combinations'] as $index => $combination) {
$count++;
$all['all']['not_used_combinations'][] = $combination;
if ($count == 100) {
if (isset($kit['variations'])) {
$all['variations'] = $kit['variations'];
unset($kit['variations']);
}
else {
$all['variations'] = $kit['product']
->getVariations();
}
$kit['product']
->setVariations($kit['creator']
->createAllProductVariations($kit['product'], [], $all))
->save();
$count = 0;
$all['all']['not_used_combinations'] = [];
}
}
if (!empty($all['all']['not_used_combinations'])) {
$all['variations'] = $kit['product']
->getVariations();
$kit['product']
->setVariations($kit['creator']
->createAllProductVariations($kit['product'], [], $all))
->save();
}
}
else {
$kit['product']
->setVariations($kit['creator']
->createAllProductVariations($kit['product'], [], $kit))
->save();
}
}
}
}