function commerce_invoice_form_commerce_order_type_form_alter in Commerce Invoice 8.2
Implements hook_form_FORM_ID_alter() for 'commerce_order_type_form'.
File
- ./
commerce_invoice.module, line 64 - Defines the Invoice entity and associated features.
Code
function commerce_invoice_form_commerce_order_type_form_alter(array &$form, FormStateInterface $form_state) {
/** @var \Drupal\commerce_order\Entity\OrderTypeInterface $order_type */
$order_type = $form_state
->getFormObject()
->getEntity();
$invoice_type_storage = \Drupal::entityTypeManager()
->getStorage('commerce_invoice_type');
$invoice_types = EntityHelper::extractLabels($invoice_type_storage
->loadMultiple());
$invoice_type_id = $order_type
->getThirdPartySetting('commerce_invoice', 'invoice_type');
$order_placed_generation = $order_type
->getThirdPartySetting('commerce_invoice', 'order_placed_generation', FALSE);
$form['commerce_invoice'] = [
'#type' => 'details',
'#title' => t('Invoice settings'),
'#weight' => 6,
'#open' => TRUE,
];
$form['commerce_invoice']['enable_invoice'] = [
'#type' => 'checkbox',
'#title' => t('Invoice orders of this type'),
'#default_value' => !empty($invoice_type_id),
];
$form['commerce_invoice']['invoice_type'] = [
'#type' => 'select',
'#title' => t('Invoice type'),
'#options' => $invoice_types,
'#default_value' => $invoice_type_id ?: key($invoice_types),
'#required' => TRUE,
'#states' => [
'visible' => [
':input[name="commerce_invoice[enable_invoice]"]' => [
'checked' => TRUE,
],
],
],
];
$form['commerce_invoice']['order_placed_generation'] = [
'#type' => 'checkbox',
'#title' => t('Invoice when the order is placed'),
'#default_value' => $order_placed_generation,
'#states' => [
'visible' => [
':input[name="commerce_invoice[enable_invoice]"]' => [
'checked' => TRUE,
],
],
],
];
$form['actions']['submit']['#submit'][] = 'commerce_invoice_order_type_form_submit';
}