class TableYamlFormExporter in YAML Form 8
Defines a HTML table exporter.
Plugin annotation
@YamlFormExporter(
id = "table",
label = @Translation("HTML Table"),
description = @Translation("Exports results as an HTML table."),
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\yamlform\YamlFormExporterBase implements YamlFormExporterInterface
- class \Drupal\yamlform\Plugin\YamlFormExporter\TabularBaseYamlFormExporter uses FileHandleTraitYamlFormExporter
- class \Drupal\yamlform\Plugin\YamlFormExporter\TableYamlFormExporter
- class \Drupal\yamlform\Plugin\YamlFormExporter\TabularBaseYamlFormExporter uses FileHandleTraitYamlFormExporter
- class \Drupal\yamlform\YamlFormExporterBase implements YamlFormExporterInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of TableYamlFormExporter
File
- src/
Plugin/ YamlFormExporter/ TableYamlFormExporter.php, line 17
Namespace
Drupal\yamlform\Plugin\YamlFormExporterView source
class TableYamlFormExporter extends TabularBaseYamlFormExporter {
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return parent::defaultConfiguration() + [
'excel' => FALSE,
];
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
if (isset($form['excel'])) {
return $form;
}
$form['excel'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Open HTML table in Excel'),
'#description' => $this
->t('If checked, the download file extension will be change from .html to .xls.'),
'#default_value' => $this->configuration['excel'],
'#states' => [
'visible' => [
[
':input.js-yamlform-exporter' => [
'value' => 'table',
],
],
],
],
];
return $form;
}
/**
* {@inheritdoc}
*/
public function writeHeader() {
$header = $this
->buildHeader();
$file_handle = $this->fileHandle;
if ($this->configuration['source_entity']) {
$title = $this->configuration['source_entity']
->label();
}
elseif ($this->configuration['yamlform']) {
$title = $this->configuration['yamlform']
->label();
}
else {
$title = '';
}
$thead = [];
foreach ($header as $item) {
$thead[] = '<th>' . htmlentities($item) . '</th>';
}
fwrite($file_handle, '<!doctype html>');
fwrite($file_handle, '<html>');
fwrite($file_handle, '<head>');
fwrite($file_handle, '<meta charset="utf-8">');
if ($title) {
fwrite($file_handle, '<title>' . $title . '</title>');
}
fwrite($file_handle, '</head>');
fwrite($file_handle, '<body>');
fwrite($file_handle, '<table border="1">');
fwrite($file_handle, '<thead><tr bgcolor="#cccccc" valign="top">');
fwrite($file_handle, implode("\n", $thead));
fwrite($file_handle, '</tr></thead>');
fwrite($file_handle, '<tbody>');
}
/**
* {@inheritdoc}
*/
public function writeSubmission(YamlFormSubmissionInterface $yamlform_submission) {
$record = $this
->buildRecord($yamlform_submission);
$file_handle = $this->fileHandle;
$row = [];
foreach ($record as $item) {
$row[] = '<td>' . htmlentities($item) . '</td>';
}
fwrite($file_handle, '<tr valign="top">');
fwrite($file_handle, implode("\n", $row));
fwrite($file_handle, '</tr>');
}
/**
* {@inheritdoc}
*/
public function writeFooter() {
$file_handle = $this->fileHandle;
fwrite($file_handle, '</tbody>');
fwrite($file_handle, '</table>');
fwrite($file_handle, '</body>');
fwrite($file_handle, '</html>');
}
/**
* {@inheritdoc}
*/
public function getFileExtension() {
return $this->configuration['excel'] ? 'xls' : 'html';
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FileHandleTraitYamlFormExporter:: |
protected | property | A file handler resource. | |
FileHandleTraitYamlFormExporter:: |
public | function | ||
FileHandleTraitYamlFormExporter:: |
public | function | ||
FileHandleTraitYamlFormExporter:: |
public | function | ||
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
TableYamlFormExporter:: |
public | function |
Form constructor. Overrides YamlFormExporterBase:: |
|
TableYamlFormExporter:: |
public | function |
Gets default configuration for this plugin. Overrides YamlFormExporterBase:: |
|
TableYamlFormExporter:: |
public | function |
Get export file extension. Overrides YamlFormExporterBase:: |
|
TableYamlFormExporter:: |
public | function |
Write footer to export. Overrides YamlFormExporterBase:: |
|
TableYamlFormExporter:: |
public | function |
Write header to export. Overrides YamlFormExporterBase:: |
|
TableYamlFormExporter:: |
public | function |
Write submission to export. Overrides YamlFormExporterBase:: |
|
TabularBaseYamlFormExporter:: |
protected | property | An associative array containing form elements keyed by name. | |
TabularBaseYamlFormExporter:: |
protected | property | An associative array containing a form's field definitions. | |
TabularBaseYamlFormExporter:: |
protected | function | Build export header using form submission field definitions and form element columns. | |
TabularBaseYamlFormExporter:: |
protected | function | Build export record using a form submission. | |
TabularBaseYamlFormExporter:: |
protected | function | Get the field definition value from a form submission entity. | |
TabularBaseYamlFormExporter:: |
protected | function | Get form elements. | |
TabularBaseYamlFormExporter:: |
protected | function | Get a form's field definitions. | |
YamlFormExporterBase:: |
protected | property | The form element manager. | |
YamlFormExporterBase:: |
protected | property | Form submission storage. | |
YamlFormExporterBase:: |
protected | property | The entity type manager. | |
YamlFormExporterBase:: |
protected | property | A logger instance. | |
YamlFormExporterBase:: |
public | function |
Calculates dependencies for the configured plugin. Overrides DependentPluginInterface:: |
|
YamlFormExporterBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
YamlFormExporterBase:: |
public | function |
Returns the results exporter description. Overrides YamlFormExporterInterface:: |
|
YamlFormExporterBase:: |
public | function |
Get archive file name for a form. Overrides YamlFormExporterInterface:: |
|
YamlFormExporterBase:: |
public | function |
Get archive file name and path for a form. Overrides YamlFormExporterInterface:: |
|
YamlFormExporterBase:: |
public | function |
Get export base file name without an extension. Overrides YamlFormExporterInterface:: |
|
YamlFormExporterBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurablePluginInterface:: |
|
YamlFormExporterBase:: |
public | function |
Get export file name. Overrides YamlFormExporterInterface:: |
|
YamlFormExporterBase:: |
public | function |
Get export file path. Overrides YamlFormExporterInterface:: |
|
YamlFormExporterBase:: |
public | function |
Get export file temp directory. Overrides YamlFormExporterInterface:: |
|
YamlFormExporterBase:: |
protected | function | Get the form source entity whose submissions are being exported. | |
YamlFormExporterBase:: |
public | function |
Returns the results exporter status. Overrides YamlFormExporterInterface:: |
|
YamlFormExporterBase:: |
public | function |
Get form submission base file name. Overrides YamlFormExporterInterface:: |
|
YamlFormExporterBase:: |
protected | function | Get the form whose submissions are being exported. | |
YamlFormExporterBase:: |
public | function |
Determine if exporter has options. Overrides YamlFormExporterInterface:: |
|
YamlFormExporterBase:: |
public | function |
Determine if exporter generates an archive. Overrides YamlFormExporterInterface:: |
|
YamlFormExporterBase:: |
public | function |
Returns the results exporter label. Overrides YamlFormExporterInterface:: |
|
YamlFormExporterBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurablePluginInterface:: |
1 |
YamlFormExporterBase:: |
public | function |
Form submission handler. Overrides PluginFormInterface:: |
|
YamlFormExporterBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
|
YamlFormExporterBase:: |
public | function |
Constructs a Drupal\Component\Plugin\PluginBase object. Overrides PluginBase:: |