TestWebformExporter.php in Webform 8.5
File
tests/modules/webform_test_exporter/src/Plugin/WebformExporter/TestWebformExporter.php
View source
<?php
namespace Drupal\webform_test_exporter\Plugin\WebformExporter;
use Drupal\Core\Form\FormStateInterface;
use Drupal\webform\Plugin\WebformExporter\TableWebformExporter;
use Drupal\webform\WebformSubmissionInterface;
class TestWebformExporter extends TableWebformExporter {
public function defaultConfiguration() {
return parent::defaultConfiguration() + [
'reverse' => TRUE,
];
}
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = parent::buildConfigurationForm($form, $form_state);
$form['reverse'] = [
'#type' => 'checkbox',
'#title' => $this
->t("Reverse the table's column order"),
'#return_value' => TRUE,
'#default_value' => $this->configuration['reverse'],
];
return $form;
}
protected function buildHeader() {
$header = parent::buildHeader();
return $this->configuration['reverse'] ? array_reverse($header) : $header;
}
protected function buildRecord(WebformSubmissionInterface $webform_submission) {
$record = parent::buildRecord($webform_submission);
return $this->configuration['reverse'] ? array_reverse($record) : $record;
}
}