public function PriceListItemExportForm::buildForm in Commerce Pricelist 8.2
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides FormInterface::buildForm
File
- src/
Form/ PriceListItemExportForm.php, line 81
Class
Namespace
Drupal\commerce_pricelist\FormCode
public function buildForm(array $form, FormStateInterface $form_state, PriceListInterface $commerce_pricelist = NULL) {
$form_state
->set('price_list_id', $commerce_pricelist
->id());
$form_state
->set('price_list_bundle', $commerce_pricelist
->bundle());
$purchasable_entity_type_id = $commerce_pricelist
->bundle();
$purchasable_entity_type = $this->entityTypeManager
->getDefinition($purchasable_entity_type_id);
$default_purchasable_entity_column = $purchasable_entity_type
->id();
if (strpos($default_purchasable_entity_column, 'commerce_') === 0) {
$default_purchasable_entity_column = str_replace('commerce_', '', $default_purchasable_entity_column);
}
$form['#tree'] = TRUE;
$form['mapping'] = [
'#type' => 'details',
'#title' => $this
->t('CSV mapping options'),
'#collapsible' => TRUE,
'#open' => TRUE,
];
$form['mapping']['purchasable_entity_column'] = [
'#type' => 'textfield',
'#title' => $this
->t('@purchasable_entity_type column', [
'@purchasable_entity_type' => $purchasable_entity_type
->getLabel(),
]),
'#default_value' => $default_purchasable_entity_column,
'#required' => TRUE,
];
$form['mapping']['purchasable_entity_label_column'] = [
'#type' => 'textfield',
'#title' => $this
->t('Label column'),
'#description' => $this
->t('Leave blank to exclude the label from the export.'),
'#default_value' => 'title',
];
$form['mapping']['quantity_column'] = [
'#type' => 'textfield',
'#title' => $this
->t('Quantity column'),
'#default_value' => 'quantity',
'#required' => TRUE,
];
$form['mapping']['list_price_column'] = [
'#type' => 'textfield',
'#title' => $this
->t('List price column'),
'#default_value' => 'list_price',
'#required' => TRUE,
];
$form['mapping']['price_column'] = [
'#type' => 'textfield',
'#title' => $this
->t('Price column'),
'#default_value' => 'price',
'#required' => TRUE,
];
$form['mapping']['currency_column'] = [
'#type' => 'textfield',
'#title' => $this
->t('Currency column'),
'#default_value' => 'currency_code',
'#required' => TRUE,
];
$form['options'] = [
'#type' => 'details',
'#title' => $this
->t('CSV file options'),
'#collapsible' => TRUE,
'#open' => FALSE,
];
$form['options']['delimiter'] = [
'#type' => 'textfield',
'#title' => $this
->t('Delimiter'),
'#size' => 5,
'#maxlength' => 1,
'#default_value' => ',',
'#required' => TRUE,
];
$form['options']['enclosure'] = [
'#type' => 'textfield',
'#title' => $this
->t('Enclosure'),
'#size' => 5,
'#maxlength' => 1,
'#default_value' => '"',
'#required' => TRUE,
];
$form['actions'] = [
'#type' => 'actions',
];
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Export prices'),
'#button_type' => 'primary',
];
return $form;
}