public function ExcelExport::buildOptionsForm in Excel Serialization 8
Same name in this branch
- 8 src/Plugin/views/display/ExcelExport.php \Drupal\xls_serialization\Plugin\views\display\ExcelExport::buildOptionsForm()
- 8 src/Plugin/views/style/ExcelExport.php \Drupal\xls_serialization\Plugin\views\style\ExcelExport::buildOptionsForm()
Provide a form to edit options for this plugin.
Overrides Serializer::buildOptionsForm
File
- src/
Plugin/ views/ style/ ExcelExport.php, line 80
Class
- ExcelExport
- A style plugin for Excel export views.
Namespace
Drupal\xls_serialization\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']);
// Remove now confusing description.
unset($form['formats']['#description']);
// XLS options.
$xls_options = $this->options['xls_settings'];
$form['xls_settings'] = [
'#type' => 'details',
'#open' => TRUE,
'#title' => $this
->t('XLS(X) settings'),
'#tree' => TRUE,
'xls_format' => [
'#type' => 'select',
'#title' => $this
->t('Format'),
'#options' => [
// @todo Add all PHPExcel supported formats.
'Excel2007' => $this
->t('Excel 2007'),
'Excel5' => $this
->t('Excel 5'),
],
'#default_value' => $xls_options['xls_format'],
],
];
$metadata = !empty($xls_options['metadata']) ? array_filter($xls_options['metadata']) : [];
// XLS metadata.
$form['xls_settings']['metadata'] = [
'#type' => 'details',
'#title' => $this
->t('Document metadata'),
'#open' => $metadata,
];
$xls_fields = [
'creator' => $this
->t('Author/creator name'),
'last_modified_by' => $this
->t('Last modified by'),
'title' => $this
->t('Title'),
'description' => $this
->t('Description'),
'subject' => $this
->t('Subject'),
'keywords' => $this
->t('Keywords'),
'category' => $this
->t('Category'),
'manager' => $this
->t('Manager'),
'company' => $this
->t('Company'),
];
foreach ($xls_fields as $xls_field_key => $xls_field_title) {
$form['xls_settings']['metadata'][$xls_field_key] = [
'#type' => 'textfield',
'#title' => $xls_field_title,
];
if (isset($xls_options['metadata'][$xls_field_key])) {
$form['xls_settings']['metadata']['#default_value'] = $xls_options['metadata'][$xls_field_key];
}
}
break;
}
}