abstract class TabularBaseYamlFormExporter in YAML Form 8
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\yamlform\YamlFormExporterBase implements YamlFormExporterInterface
- 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 TabularBaseYamlFormExporter
File
- src/
Plugin/ YamlFormExporter/ TabularBaseYamlFormExporter.php, line 11
Namespace
Drupal\yamlform\Plugin\YamlFormExporterView source
abstract class TabularBaseYamlFormExporter extends YamlFormExporterBase {
use FileHandleTraitYamlFormExporter;
/**
* An associative array containing form elements keyed by name.
*
* @var array
*/
protected $elements;
/**
* An associative array containing a form's field definitions.
*
* @var array
*/
protected $fieldDefinitions;
/****************************************************************************/
// Header.
/****************************************************************************/
/**
* Build export header using form submission field definitions and form 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 form element for each field definition so that we can
// use YamlFormElement::buildExportHeader(array $element, $export_options).
$element = [
'#type' => $field_definition['type'] == 'entity_reference' ? 'entity_autocomplete' : 'element',
'#admin_title' => '',
'#title' => (string) $field_definition['title'],
'#yamlform_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 form submission.
*
* @param \Drupal\yamlform\YamlFormSubmissionInterface $yamlform_submission
* A form submission.
*
* @return array
* An array containing the export record.
*/
protected function buildRecord(YamlFormSubmissionInterface $yamlform_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, $yamlform_submission, $field_definition);
}
// Build record element columns.
$data = $yamlform_submission
->getData();
foreach ($elements as $column_name => $element) {
$value = isset($data[$column_name]) ? $data[$column_name] : '';
$record = array_merge($record, $this->elementManager
->invokeMethod('buildExportRecord', $element, $value, $export_options));
}
return $record;
}
/**
* Get the field definition value from a form submission entity.
*
* @param array $record
* The record to be added to the export file.
* @param \Drupal\yamlform\YamlFormSubmissionInterface $yamlform_submission
* A form submission.
* @param array $field_definition
* The field definition for the value.
*/
protected function formatRecordFieldDefinitionValue(array &$record, YamlFormSubmissionInterface $yamlform_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':
$record[] = date('Y-m-d H:i:s', $yamlform_submission
->get($field_name)->value);
break;
case 'entity_reference':
$element = [
'#type' => 'entity_autocomplete',
'#target_type' => $field_definition['target_type'],
];
$value = $yamlform_submission
->get($field_name)->target_id;
$record = array_merge($record, $this->elementManager
->invokeMethod('buildExportRecord', $element, $value, $export_options));
break;
case 'entity_url':
case 'entity_title':
if (empty($yamlform_submission->entity_type->value) || empty($yamlform_submission->entity_id->value)) {
$record[] = '';
break;
}
$entity_type = $yamlform_submission->entity_type->value;
$entity_id = $yamlform_submission->entity_id->value;
$entity = $this->entityTypeManager
->getStorage($entity_type)
->load($entity_id);
if ($entity) {
$record[] = $field_type == 'entity_url' ? $entity
->toUrl()
->setOption('absolute', TRUE)
->toString() : $entity
->label();
}
else {
$record[] = '';
}
break;
default:
$record[] = $yamlform_submission
->get($field_name)->value;
break;
}
}
/****************************************************************************/
// Form definitions and elements.
/****************************************************************************/
/**
* Get a form's field definitions.
*
* @return array
* An associative array containing a form's field definitions.
*/
protected function getFieldDefinitions() {
if (isset($this->fieldDefinitions)) {
return $this->fieldDefinitions;
}
$export_options = $this
->getConfiguration();
$this->fieldDefinitions = $this->entityStorage
->getFieldDefinitions();
$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 ($export_options['entity_reference_format'] == 'link' && isset($this->fieldDefinitions['entity_type']) && isset($this->fieldDefinitions['entity_id'])) {
$this->fieldDefinitions['entity_title'] = [
'name' => 'entity_title',
'title' => t('Submitted to: Entity title'),
'type' => 'entity_title',
];
$this->fieldDefinitions['entity_url'] = [
'name' => 'entity_url',
'title' => t('Submitted to: Entity URL'),
'type' => 'entity_url',
];
}
return $this->fieldDefinitions;
}
/**
* Get form elements.
*
* @return array
* An associative array containing form elements keyed by name.
*/
protected function getElements() {
if (isset($this->elements)) {
return $this->elements;
}
$export_options = $this
->getConfiguration();
$yamlform = $this
->getYamlForm();
$element_columns = $yamlform
->getElementsFlattenedAndHasValue();
$this->elements = array_diff_key($element_columns, $export_options['excluded_columns']);
return $this->elements;
}
}
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. | |
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 |
Form constructor. Overrides PluginFormInterface:: |
3 |
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 |
Gets default configuration for this plugin. Overrides ConfigurablePluginInterface:: |
3 |
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 extension. Overrides YamlFormExporterInterface:: |
2 |
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 |
Write footer to export. Overrides YamlFormExporterInterface:: |
1 |
YamlFormExporterBase:: |
public | function |
Write header to export. Overrides YamlFormExporterInterface:: |
2 |
YamlFormExporterBase:: |
public | function |
Write submission to export. Overrides YamlFormExporterInterface:: |
4 |
YamlFormExporterBase:: |
public | function |
Constructs a Drupal\Component\Plugin\PluginBase object. Overrides PluginBase:: |