public function StockConfigForm::submitForm in Commerce Stock 8
Throws
\Drupal\Component\Plugin\Exception\PluginException
Overrides ConfigFormBase::submitForm
File
- src/
Form/ StockConfigForm.php, line 198
Class
- StockConfigForm
- The stock configuration form.
Namespace
Drupal\commerce_stock\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$values = $form_state
->getValues();
$config = $this
->config('commerce_stock.service_manager');
$config
->set('default_service_id', $values['default_service_id']);
foreach ($this->purchasableEntityTypes as $entity_type_id => $entity_type_info) {
foreach (array_keys($entity_type_info['bundles']) as $bundle_id) {
$key = $entity_type_id . '_' . $bundle_id . '_service_id';
$value = $values[$key];
if ($value !== 'use_default') {
$config
->set($key, $value);
}
else {
$config
->clear($key);
}
}
}
// Events manager.
$config
->set('stock_events_plugin_id', $values['selected_event_plugin']);
$config
->save();
// Update all plugin options.
$type = $this->stockEventsManager;
$plugin_definitions = $type
->getDefinitions();
foreach ($plugin_definitions as $plugin_definition) {
$id = $plugin_definition['id'];
$plugin = $type
->createInstance($id);
$plugin
->SaveconfigFormOptions($form, $form_state);
}
$this
->messenger()
->addMessage($this
->t('Stock configuration updated.'));
}