public function CommerceTurnoverSensorPlugin::buildConfigurationForm in Monitoring 8
Adds additional settings to the sensor configuration form.
Overrides ContentEntityAggregatorSensorPlugin::buildConfigurationForm
File
- src/
Plugin/ monitoring/ SensorPlugin/ CommerceTurnoverSensorPlugin.php, line 132
Class
- CommerceTurnoverSensorPlugin
- Monitors commerce order turnover stats.
Namespace
Drupal\monitoring\Plugin\monitoring\SensorPluginCode
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = parent::buildConfigurationForm($form, $form_state);
$form['commerce_order_paid_states'] = [
'#type' => 'checkboxes',
'#title' => t('"Paid" order states'),
'#description' => t('Select order states in which the order is considered to be paid.'),
'#options' => $this
->getOrderStates(),
'#default_value' => $this->sensorConfig
->getSetting('commerce_order_paid_states'),
];
$currencies = $this->entityTypeManager
->getStorage('commerce_currency')
->loadMultiple();
$current_store = $this->currentStore
->getStore();
$default_currency = $current_store
->getDefaultCurrency();
foreach ($currencies as $currency_code => $currency) {
$currencies[$currency_code] = $currency
->getName();
}
$selected_currency = $this->sensorConfig
->getSetting('commerce_order_currency') ?: '';
if (empty($selected_currency) && $default_currency instanceof CurrencyInterface) {
$selected_currency = $default_currency
->getCurrencyCode();
}
$form['commerce_order_currency'] = [
'#type' => 'select',
'#title' => t('Currency'),
'#description' => t('Select which currency the orders are using.'),
'#options' => $currencies,
'#default_value' => $selected_currency,
'#required' => TRUE,
];
return $form;
}