You are here

class WebformSubmissionExportImportWebformExporter in Webform 8.5

Same name and namespace in other branches
  1. 6.x modules/webform_submission_export_import/src/Plugin/WebformExporter/WebformSubmissionExportImportWebformExporter.php \Drupal\webform_submission_export_import\Plugin\WebformExporter\WebformSubmissionExportImportWebformExporter

Defines a machine readable CSV export that can be imported back into the current webform.

Plugin annotation


@WebformExporter(
  id = "webform_submission_export_import",
  label = @Translation("CSV download"),
  description = @Translation("Exports results in CSV that can be imported back into the current webform."),
  archive = FALSE,
  files = FALSE,
  options = FALSE,
)

Hierarchy

Expanded class hierarchy of WebformSubmissionExportImportWebformExporter

File

modules/webform_submission_export_import/src/Plugin/WebformExporter/WebformSubmissionExportImportWebformExporter.php, line 22

Namespace

Drupal\webform_submission_export_import\Plugin\WebformExporter
View source
class WebformSubmissionExportImportWebformExporter extends WebformExporterBase {
  use FileHandleTraitWebformExporter;

  /**
   * {@inheritdoc}
   */
  public function defaultConfiguration() {
    return parent::defaultConfiguration() + [
      'uuid' => TRUE,
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    $form = parent::buildConfigurationForm($form, $form_state);
    $form['warning'] = [
      '#type' => 'webform_message',
      '#message_type' => 'warning',
      '#message_message' => $this
        ->t('<strong>Warning:</strong> Opening delimited text files with spreadsheet applications may expose you to <a href=":href">formula injection</a> or other security vulnerabilities. When the submissions contain data from untrusted users and the downloaded file will be used with Microsoft Excel, use \'HTML table\' format.', [
        ':href' => 'https://www.google.com/search?q=spreadsheet+formula+injection',
      ]),
    ];
    $form['uuid'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Use UUIDs for all entity references'),
      '#description' => $this
        ->t("If checked, all entity references will use the entity's UUID"),
      '#return_value' => TRUE,
      '#default_value' => $this->configuration['uuid'],
    ];
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function getFileExtension() {
    return 'csv';
  }

  /**
   * {@inheritdoc}
   */
  public function writeHeader() {
    $header = $this
      ->getImporter()
      ->exportHeader();
    fputcsv($this->fileHandle, $header);
  }

  /**
   * {@inheritdoc}
   */
  public function writeSubmission(WebformSubmissionInterface $webform_submission) {
    $record = $this
      ->getImporter()
      ->exportSubmission($webform_submission, $this->configuration);
    fputcsv($this->fileHandle, $record);
  }

  /**
   * Get the submission importer.
   *
   * @return \Drupal\webform_submission_export_import\WebformSubmissionExportImportImporterInterface
   *   The submission importer.
   */
  protected function getImporter() {

    /** @var \Drupal\webform_submission_export_import\WebformSubmissionExportImportImporterInterface $importer */
    $importer = \Drupal::service('webform_submission_export_import.importer');
    $importer
      ->setWebform($this
      ->getWebform());
    return $importer;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
FileHandleTraitWebformExporter::$fileHandle protected property A file handler resource.
FileHandleTraitWebformExporter::closeExport public function
FileHandleTraitWebformExporter::createExport public function
FileHandleTraitWebformExporter::openExport public function
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
WebformExporterBase::$archive protected property Cached archive object.
WebformExporterBase::$configFactory protected property The configuration factory.
WebformExporterBase::$elementManager protected property The webform element manager.
WebformExporterBase::$entityStorage protected property The webform submission storage.
WebformExporterBase::$entityTypeManager protected property The entity type manager.
WebformExporterBase::$logger protected property A logger instance.
WebformExporterBase::$tokenManager protected property The webform token manager.
WebformExporterBase::addToArchive public function Add file, directory, or content to exporter archive. Overrides WebformExporterInterface::addToArchive
WebformExporterBase::addToTarArchive protected function Add file, directory, or content to Tar archive.
WebformExporterBase::addToZipFile protected function Add file, directory, or content to ZIP file.
WebformExporterBase::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create 1
WebformExporterBase::description public function Returns the results exporter description. Overrides WebformExporterInterface::description
WebformExporterBase::getArchiveFileExtension public function Get archive file extension for a webform. Overrides WebformExporterInterface::getArchiveFileExtension
WebformExporterBase::getArchiveFileName public function Get archive file name for a webform. Overrides WebformExporterInterface::getArchiveFileName
WebformExporterBase::getArchiveFilePath public function Get archive file name and path for a webform. Overrides WebformExporterInterface::getArchiveFilePath
WebformExporterBase::getArchiveType public function Get archive file type. Overrides WebformExporterInterface::getArchiveType
WebformExporterBase::getBaseFileName public function Get export base file name without an extension. Overrides WebformExporterInterface::getBaseFileName
WebformExporterBase::getBatchLimit public function Get the number of submissions to be exported with each batch. Overrides WebformExporterInterface::getBatchLimit 1
WebformExporterBase::getConfiguration public function Gets this plugin's configuration. Overrides ConfigurableInterface::getConfiguration
WebformExporterBase::getExportFileName public function Get export file name. Overrides WebformExporterInterface::getExportFileName
WebformExporterBase::getExportFilePath public function Get export file path. Overrides WebformExporterInterface::getExportFilePath
WebformExporterBase::getFileTempDirectory public function Get export file temp directory. Overrides WebformExporterInterface::getFileTempDirectory
WebformExporterBase::getSourceEntity protected function Get the webform source entity whose submissions are being exported.
WebformExporterBase::getStatus public function Returns the results exporter status. Overrides WebformExporterInterface::getStatus
WebformExporterBase::getSubmissionBaseName public function Get webform submission base file name. Overrides WebformExporterInterface::getSubmissionBaseName
WebformExporterBase::getWebform protected function Get the webform whose submissions are being exported.
WebformExporterBase::hasFiles public function Determine if exporter can include uploaded files (in a zipped archive). Overrides WebformExporterInterface::hasFiles
WebformExporterBase::hasOptions public function Determine if exporter has options. Overrides WebformExporterInterface::hasOptions
WebformExporterBase::isArchive public function Determine if exporter generates an archive. Overrides WebformExporterInterface::isArchive
WebformExporterBase::isExcluded public function Checks if the exporter is excluded via webform.settings. Overrides WebformExporterInterface::isExcluded
WebformExporterBase::label public function Returns the results exporter label. Overrides WebformExporterInterface::label
WebformExporterBase::setConfiguration public function Sets the configuration for this plugin instance. Overrides ConfigurableInterface::setConfiguration 1
WebformExporterBase::submitConfigurationForm public function Form submission handler. Overrides PluginFormInterface::submitConfigurationForm
WebformExporterBase::validateConfigurationForm public function Form validation handler. Overrides PluginFormInterface::validateConfigurationForm
WebformExporterBase::writeFooter public function Write footer to export. Overrides WebformExporterInterface::writeFooter 1
WebformExporterBase::__construct public function Constructs a WebformExporterBase object. Overrides PluginBase::__construct 1
WebformExporterInterface::ARCHIVE_TAR constant Tar archive.
WebformExporterInterface::ARCHIVE_ZIP constant ZIP file.
WebformSubmissionExportImportWebformExporter::buildConfigurationForm public function Form constructor. Overrides WebformExporterBase::buildConfigurationForm
WebformSubmissionExportImportWebformExporter::defaultConfiguration public function Gets default configuration for this plugin. Overrides WebformExporterBase::defaultConfiguration
WebformSubmissionExportImportWebformExporter::getFileExtension public function Get export file extension. Overrides WebformExporterBase::getFileExtension
WebformSubmissionExportImportWebformExporter::getImporter protected function Get the submission importer.
WebformSubmissionExportImportWebformExporter::writeHeader public function Write header to export. Overrides WebformExporterBase::writeHeader
WebformSubmissionExportImportWebformExporter::writeSubmission public function Write submission to export. Overrides WebformExporterBase::writeSubmission