abstract class TabularBaseWebformExporter in Webform 6.x
Same name and namespace in other branches
- 8.5 src/Plugin/WebformExporter/TabularBaseWebformExporter.php \Drupal\webform\Plugin\WebformExporter\TabularBaseWebformExporter
Defines abstract tabular exporter used to build CSV files and HTML tables.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\webform\Plugin\WebformExporterBase implements WebformExporterInterface uses WebformEntityStorageTrait
- class \Drupal\webform\Plugin\WebformExporter\TabularBaseWebformExporter uses FileHandleTraitWebformExporter
- class \Drupal\webform\Plugin\WebformExporterBase implements WebformExporterInterface uses WebformEntityStorageTrait
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of TabularBaseWebformExporter
File
- src/
Plugin/ WebformExporter/ TabularBaseWebformExporter.php, line 12
Namespace
Drupal\webform\Plugin\WebformExporterView source
abstract class TabularBaseWebformExporter extends WebformExporterBase {
use FileHandleTraitWebformExporter;
/**
* The date formatter service.
*
* @var \Drupal\Core\Datetime\DateFormatterInterface
*/
protected $dateFormatter;
/**
* An associative array containing webform elements keyed by name.
*
* @var array
*/
protected $elements;
/**
* An associative array containing a webform's field definitions.
*
* @var array
*/
protected $fieldDefinitions;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
$instance = parent::create($container, $configuration, $plugin_id, $plugin_definition);
$instance->dateFormatter = $container
->get('date.formatter');
return $instance;
}
/****************************************************************************/
// Header.
/****************************************************************************/
/**
* Build export header using webform submission field definitions and webform element columns.
*
* @return array
* An array containing the export header.
*/
protected function buildHeader() {
$export_options = $this
->getConfiguration();
$this->fieldDefinitions = $this
->getFieldDefinitions();
$elements = $this
->getElements();
$header = [];
foreach ($this->fieldDefinitions as $field_definition) {
// Build a webform element for each field definition so that we can
// use WebformElement::buildExportHeader(array $element, $export_options).
$element = [
'#type' => $field_definition['type'] === 'entity_reference' ? 'entity_autocomplete' : 'element',
'#admin_title' => '',
'#title' => (string) $field_definition['title'],
'#webform_key' => (string) $field_definition['name'],
];
$header = array_merge($header, $this->elementManager
->invokeMethod('buildExportHeader', $element, $export_options));
}
// Build element columns headers.
foreach ($elements as $element) {
$header = array_merge($header, $this->elementManager
->invokeMethod('buildExportHeader', $element, $export_options));
}
return $header;
}
/****************************************************************************/
// Record.
/****************************************************************************/
/**
* Build export record using a webform submission.
*
* @param \Drupal\webform\WebformSubmissionInterface $webform_submission
* A webform submission.
*
* @return array
* An array containing the export record.
*/
protected function buildRecord(WebformSubmissionInterface $webform_submission) {
$export_options = $this
->getConfiguration();
$this->fieldDefinitions = $this
->getFieldDefinitions();
$elements = $this
->getElements();
$record = [];
// Build record field definition columns.
foreach ($this->fieldDefinitions as $field_definition) {
$this
->formatRecordFieldDefinitionValue($record, $webform_submission, $field_definition);
}
// Build record element columns.
foreach ($elements as $column_name => $element) {
$element['#webform_key'] = $column_name;
$record = array_merge($record, $this->elementManager
->invokeMethod('buildExportRecord', $element, $webform_submission, $export_options));
}
return $record;
}
/**
* Get the field definition value from a webform submission entity.
*
* @param array $record
* The record to be added to the export file.
* @param \Drupal\webform\WebformSubmissionInterface $webform_submission
* A webform submission.
* @param array $field_definition
* The field definition for the value.
*/
protected function formatRecordFieldDefinitionValue(array &$record, WebformSubmissionInterface $webform_submission, array $field_definition) {
$export_options = $this
->getConfiguration();
$field_name = $field_definition['name'];
$field_type = $field_definition['type'];
switch ($field_type) {
case 'created':
case 'changed':
case 'timestamp':
if (!empty($webform_submission->{$field_name}->value)) {
$record[] = $this->dateFormatter
->format($webform_submission->{$field_name}->value, 'custom', 'Y-m-d H:i:s');
}
else {
$record[] = '';
}
break;
case 'entity_reference':
$element = [
'#type' => 'entity_autocomplete',
'#target_type' => $field_definition['target_type'],
'#value' => $webform_submission
->get($field_name)->target_id,
];
$record = array_merge($record, $this->elementManager
->invokeMethod('buildExportRecord', $element, $webform_submission, $export_options));
break;
case 'entity_url':
case 'entity_title':
$entity = $webform_submission
->getSourceEntity(TRUE);
if ($entity) {
$record[] = $field_type === 'entity_url' && $entity
->hasLinkTemplate('canonical') ? $entity
->toUrl()
->setOption('absolute', TRUE)
->toString() : $entity
->label();
}
else {
$record[] = '';
}
break;
default:
$record[] = $webform_submission
->get($field_name)->value;
break;
}
}
/****************************************************************************/
// Webform definitions and elements.
/****************************************************************************/
/**
* Get a webform's field definitions.
*
* @return array
* An associative array containing a webform's field definitions.
*/
protected function getFieldDefinitions() {
if (isset($this->fieldDefinitions)) {
return $this->fieldDefinitions;
}
$export_options = $this
->getConfiguration();
$this->fieldDefinitions = $this
->getSubmissionStorage()
->getFieldDefinitions();
$this->fieldDefinitions = $this
->getSubmissionStorage()
->checkFieldDefinitionAccess($this
->getWebform(), $this->fieldDefinitions);
if ($export_options['excluded_columns']) {
$this->fieldDefinitions = array_diff_key($this->fieldDefinitions, $export_options['excluded_columns']);
}
// Add custom entity reference field definitions which rely on the
// entity type and entity id.
if (isset($this->fieldDefinitions['entity_type']) && isset($this->fieldDefinitions['entity_id'])) {
$this->fieldDefinitions['entity_title'] = [
'name' => 'entity_title',
'title' => $this
->t('Submitted to: Entity title'),
'type' => 'entity_title',
];
$this->fieldDefinitions['entity_url'] = [
'name' => 'entity_url',
'title' => $this
->t('Submitted to: Entity URL'),
'type' => 'entity_url',
];
}
return $this->fieldDefinitions;
}
/**
* Get webform elements.
*
* @return array
* An associative array containing webform elements keyed by name.
*/
protected function getElements() {
if (isset($this->elements)) {
return $this->elements;
}
$export_options = $this
->getConfiguration();
$this->elements = $this
->getWebform()
->getElementsInitializedFlattenedAndHasValue('view');
// Replace tokens which can be used in an element's #title.
$this->elements = $this->tokenManager
->replace($this->elements, $this
->getWebform());
if ($export_options['excluded_columns']) {
$this->elements = array_diff_key($this->elements, $export_options['excluded_columns']);
}
return $this->elements;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
public | function | 2 | |
DependencySerializationTrait:: |
public | function | 2 | |
FileHandleTraitWebformExporter:: |
protected | property | A file handler resource. | |
FileHandleTraitWebformExporter:: |
public | function | ||
FileHandleTraitWebformExporter:: |
public | function | ||
FileHandleTraitWebformExporter:: |
public | function | ||
MessengerTrait:: |
protected | property | The messenger. | 27 |
MessengerTrait:: |
public | function | Gets the messenger. | 27 |
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:: |
2 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
PluginBase:: |
public | function | Constructs a \Drupal\Component\Plugin\PluginBase object. | 98 |
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
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. | |
TabularBaseWebformExporter:: |
protected | property | The date formatter service. | |
TabularBaseWebformExporter:: |
protected | property | An associative array containing webform elements keyed by name. | |
TabularBaseWebformExporter:: |
protected | property | An associative array containing a webform's field definitions. | |
TabularBaseWebformExporter:: |
protected | function | Build export header using webform submission field definitions and webform element columns. | 1 |
TabularBaseWebformExporter:: |
protected | function | Build export record using a webform submission. | 2 |
TabularBaseWebformExporter:: |
public static | function |
Creates an instance of the plugin. Overrides WebformExporterBase:: |
|
TabularBaseWebformExporter:: |
protected | function | Get the field definition value from a webform submission entity. | |
TabularBaseWebformExporter:: |
protected | function | Get webform elements. | |
TabularBaseWebformExporter:: |
protected | function | Get a webform's field definitions. | |
WebformEntityStorageTrait:: |
protected | property | An associate array of entity type storage aliases. | |
WebformEntityStorageTrait:: |
protected | property | The entity type manager. | 5 |
WebformEntityStorageTrait:: |
protected | function | Retrieves the entity storage. | |
WebformEntityStorageTrait:: |
protected | function | Retrieves the webform submission storage. | |
WebformEntityStorageTrait:: |
protected | function | Retrieves the webform storage. | |
WebformEntityStorageTrait:: |
public | function | Implements the magic __get() method. | |
WebformExporterBase:: |
protected | property | Cached archive object. | |
WebformExporterBase:: |
protected | property | The configuration factory. | |
WebformExporterBase:: |
protected | property | The webform element manager. | |
WebformExporterBase:: |
protected | property | A logger instance. | |
WebformExporterBase:: |
protected | property | The webform token manager. | |
WebformExporterBase:: |
public | function |
Add file, directory, or content to exporter archive. Overrides WebformExporterInterface:: |
|
WebformExporterBase:: |
protected | function | Add file, directory, or content to Tar archive. | |
WebformExporterBase:: |
protected | function | Add file, directory, or content to ZIP file. | |
WebformExporterBase:: |
public | function |
Form constructor. Overrides PluginFormInterface:: |
4 |
WebformExporterBase:: |
public | function |
Gets default configuration for this plugin. Overrides ConfigurableInterface:: |
4 |
WebformExporterBase:: |
public | function |
Returns the results exporter description. Overrides WebformExporterInterface:: |
|
WebformExporterBase:: |
public | function |
Get archive file extension for a webform. Overrides WebformExporterInterface:: |
|
WebformExporterBase:: |
public | function |
Get archive file name for a webform. Overrides WebformExporterInterface:: |
|
WebformExporterBase:: |
public | function |
Get archive file name and path for a webform. Overrides WebformExporterInterface:: |
|
WebformExporterBase:: |
public | function |
Get archive file type. Overrides WebformExporterInterface:: |
|
WebformExporterBase:: |
public | function |
Get export base file name without an extension. Overrides WebformExporterInterface:: |
|
WebformExporterBase:: |
public | function |
Get the number of submissions to be exported with each batch. Overrides WebformExporterInterface:: |
1 |
WebformExporterBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
WebformExporterBase:: |
public | function |
Get export file name. Overrides WebformExporterInterface:: |
|
WebformExporterBase:: |
public | function |
Get export file path. Overrides WebformExporterInterface:: |
|
WebformExporterBase:: |
public | function |
Get export file extension. Overrides WebformExporterInterface:: |
3 |
WebformExporterBase:: |
public | function |
Get export file temp directory. Overrides WebformExporterInterface:: |
|
WebformExporterBase:: |
protected | function | Get the webform source entity whose submissions are being exported. | |
WebformExporterBase:: |
public | function |
Returns the results exporter status. Overrides WebformExporterInterface:: |
|
WebformExporterBase:: |
public | function |
Get webform submission base file name. Overrides WebformExporterInterface:: |
|
WebformExporterBase:: |
protected | function | Get the webform whose submissions are being exported. | |
WebformExporterBase:: |
public | function |
Determine if exporter can include uploaded files (in a zipped archive). Overrides WebformExporterInterface:: |
|
WebformExporterBase:: |
public | function |
Determine if exporter has options. Overrides WebformExporterInterface:: |
|
WebformExporterBase:: |
public | function |
Determine if exporter generates an archive. Overrides WebformExporterInterface:: |
|
WebformExporterBase:: |
public | function |
Checks if the exporter is excluded via webform.settings. Overrides WebformExporterInterface:: |
|
WebformExporterBase:: |
public | function |
Returns the results exporter label. Overrides WebformExporterInterface:: |
|
WebformExporterBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
1 |
WebformExporterBase:: |
public | function |
Form submission handler. Overrides PluginFormInterface:: |
|
WebformExporterBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
|
WebformExporterBase:: |
public | function |
Write footer to export. Overrides WebformExporterInterface:: |
1 |
WebformExporterBase:: |
public | function |
Write header to export. Overrides WebformExporterInterface:: |
3 |
WebformExporterBase:: |
public | function |
Write submission to export. Overrides WebformExporterInterface:: |
6 |
WebformExporterInterface:: |
constant | Tar archive. | ||
WebformExporterInterface:: |
constant | ZIP file. |