public function DataExport::buildOptionsForm in Views data export 8
Same name in this branch
- 8 src/Plugin/views/display/DataExport.php \Drupal\views_data_export\Plugin\views\display\DataExport::buildOptionsForm()
- 8 src/Plugin/views/style/DataExport.php \Drupal\views_data_export\Plugin\views\style\DataExport::buildOptionsForm()
Provide a form to edit options for this plugin.
Overrides Serializer::buildOptionsForm
File
- src/
Plugin/ views/ style/ DataExport.php, line 59
Class
- DataExport
- A style plugin for data export views.
Namespace
Drupal\views_data_export\Plugin\views\styleCode
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
switch ($form_state
->get('section')) {
case 'style_options':
// Change format to radios instead, since multiple formats here do not
// make sense as they do for REST exports.
$form['formats']['#type'] = 'radios';
$form['formats']['#default_value'] = reset($this->options['formats']);
$format_options = $this
->getFormatOptions();
if (in_array('csv', $format_options)) {
// CSV options.
// @todo Can these be moved to a plugin?
$csv_options = $this->options['csv_settings'];
$form['csv_settings'] = [
'#type' => 'details',
'#open' => FALSE,
'#title' => $this
->t('CSV settings'),
'#tree' => TRUE,
'#states' => [
'visible' => [
':input[name="style_options[formats]"]' => [
'value' => 'csv',
],
],
],
'delimiter' => [
'#type' => 'textfield',
'#title' => $this
->t('Delimiter'),
'#description' => $this
->t('Indicates the character used to delimit fields. Defaults to a comma (<code>,</code>). For tab-separation use <code>\\t</code> characters.'),
'#default_value' => $csv_options['delimiter'],
],
'enclosure' => [
'#type' => 'textfield',
'#title' => $this
->t('Enclosure'),
'#description' => $this
->t('Indicates the character used for field enclosure. Defaults to a double quote (<code>"</code>).'),
'#default_value' => $csv_options['enclosure'],
],
'escape_char' => [
'#type' => 'textfield',
'#title' => $this
->t('Escape character'),
'#description' => $this
->t('Indicates the character used for escaping. Defaults to a backslash (<code>\\</code>).'),
'#default_value' => $csv_options['escape_char'],
],
'strip_tags' => [
'#type' => 'checkbox',
'#title' => $this
->t('Strip HTML'),
'#description' => $this
->t('Strips HTML tags from CSV cell values.'),
'#default_value' => $csv_options['strip_tags'],
],
'trim' => [
'#type' => 'checkbox',
'#title' => $this
->t('Trim whitespace'),
'#description' => $this
->t('Trims whitespace from beginning and end of CSV cell values.'),
'#default_value' => $csv_options['trim'],
],
'encoding' => [
'#type' => 'radios',
'#title' => $this
->t('Encoding'),
'#description' => $this
->t('Determines the encoding used for CSV cell values.'),
'#options' => [
'utf8' => $this
->t('UTF-8'),
],
'#default_value' => $csv_options['encoding'],
],
'utf8_bom' => [
'#type' => 'checkbox',
'#title' => $this
->t('Include unicode signature (<a href="@bom" target="_blank">BOM</a>).', [
'@bom' => 'https://www.w3.org/International/questions/qa-byte-order-mark',
]),
'#default_value' => $csv_options['utf8_bom'],
],
'use_serializer_encode_only' => [
'#type' => 'checkbox',
'#title' => $this
->t('Only use Symfony serializer->encode method'),
'#description' => $this
->t('Skips the symfony data normalize method when rendering data export to increase performance on large datasets. <strong>(Only use when not exporting nested data)</strong>'),
'#default_value' => $csv_options['use_serializer_encode_only'],
],
];
}
break;
}
}