class WebformEntityPrintWebformExporter in Webform 6.x
Same name and namespace in other branches
- 8.5 modules/webform_entity_print/src/Plugin/WebformExporter/WebformEntityPrintWebformExporter.php \Drupal\webform_entity_print\Plugin\WebformExporter\WebformEntityPrintWebformExporter
Defines a Webform Entity Print PDF exporter.
Plugin annotation
@WebformExporter(
id = "webform_entity_print",
archive = TRUE,
options = FALSE,
deriver = "Drupal\webform_entity_print\Plugin\Derivative\WebformEntityPrintWebformExporterDeriver",
)
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\DocumentBaseWebformExporter
- class \Drupal\webform_entity_print\Plugin\WebformExporter\WebformEntityPrintWebformExporter
- class \Drupal\webform\Plugin\WebformExporter\DocumentBaseWebformExporter
- class \Drupal\webform\Plugin\WebformExporterBase implements WebformExporterInterface uses WebformEntityStorageTrait
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of WebformEntityPrintWebformExporter
File
- modules/
webform_entity_print/ src/ Plugin/ WebformExporter/ WebformEntityPrintWebformExporter.php, line 20
Namespace
Drupal\webform_entity_print\Plugin\WebformExporterView source
class WebformEntityPrintWebformExporter extends DocumentBaseWebformExporter {
/**
* The current request.
*
* @var \Symfony\Component\HttpFoundation\Request
*/
protected $request;
/**
* The plugin manager for our Print engines.
*
* @var \Drupal\entity_print\Plugin\EntityPrintPluginManagerInterface
*/
protected $printEngineManager;
/**
* The export type manager.
*
* @var \Drupal\entity_print\Plugin\ExportTypeManagerInterface
*/
protected $exportTypeManager;
/**
* The file system service.
*
* @var \Drupal\Core\File\FileSystemInterface
*/
protected $fileSystem;
/**
* The Print builder.
*
* @var \Drupal\entity_print\PrintBuilderInterface
*/
protected $printBuilder;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
$instance = parent::create($container, $configuration, $plugin_id, $plugin_definition);
$instance->request = $container
->get('request_stack')
->getCurrentRequest();
$instance->printEngineManager = $container
->get('plugin.manager.entity_print.print_engine');
$instance->exportTypeManager = $container
->get('plugin.manager.entity_print.export_type');
$instance->printBuilder = $container
->get('entity_print.print_builder');
$instance->fileSystem = $container
->get('file_system');
return $instance;
}
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return parent::defaultConfiguration() + [
'view_mode' => 'html',
];
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = parent::buildConfigurationForm($form, $form_state);
$form['view_mode'] = [
'#type' => 'select',
'#title' => $this
->t('View mode'),
'#options' => [
'html' => $this
->t('HTML'),
'table' => $this
->t('Table'),
],
'#required' => TRUE,
'#default_value' => $this->configuration['view_mode'],
];
return $form;
}
/**
* {@inheritdoc}
*/
public function writeSubmission(WebformSubmissionInterface $webform_submission) {
$configuration = $this
->getConfiguration();
// Make sure Webform Entity Print template is used.
// @see webform_entity_print_entity_view_alter()
$this->request->request
->set('_webform_entity_print', TRUE);
// Set view mode.
// @see \Drupal\webform\WebformSubmissionViewBuilder::view
$this->request->request
->set('_webform_submissions_view_mode', $configuration['view_mode']);
// Get print engine.
$export_type_id = $this
->getExportTypeId();
$print_engine = $this->printEngineManager
->createSelectedInstance($export_type_id);
// Get scheme.
$scheme = 'temporary';
// Get file name.
$file_extension = $this
->getExportTypeFileExtension();
$file_name = $this
->getSubmissionBaseName($webform_submission) . '.' . $file_extension;
// Save printable document.
$temporary_file_path = $this->printBuilder
->savePrintable([
$webform_submission,
], $print_engine, $scheme, $file_name);
if ($temporary_file_path) {
$this
->addToArchive(file_get_contents($temporary_file_path), $file_name);
$this->fileSystem
->delete($temporary_file_path);
}
}
/**
* {@inheritdoc}
*/
public function getBatchLimit() {
// Limit batch document export to 10 submissions.
return 10;
}
/****************************************************************************/
// Export type methods.
/****************************************************************************/
/**
* Get export type id.
*
* @return string
* The export type id.
*/
protected function getExportTypeId() {
return str_replace('webform_entity_print:', '', $this
->getPluginId());
}
/**
* Get export type definition.
*
* @return array
* Export type definition.
*/
protected function getExportTypeDefinition() {
$export_type_id = $this
->getExportTypeId();
return $this->exportTypeManager
->getDefinition($export_type_id);
}
/**
* Get export type file extension.
*
* @return string
* Export type file extension.
*/
protected function getExportTypeFileExtension() {
$definition = $this
->getExportTypeDefinition();
return $definition['file_extension'];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
public | function | 2 | |
DependencySerializationTrait:: |
public | function | 2 | |
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. | |
WebformEntityPrintWebformExporter:: |
protected | property | The export type manager. | |
WebformEntityPrintWebformExporter:: |
protected | property | The file system service. | |
WebformEntityPrintWebformExporter:: |
protected | property | The Print builder. | |
WebformEntityPrintWebformExporter:: |
protected | property | The plugin manager for our Print engines. | |
WebformEntityPrintWebformExporter:: |
protected | property | The current request. | |
WebformEntityPrintWebformExporter:: |
public | function |
Form constructor. Overrides DocumentBaseWebformExporter:: |
|
WebformEntityPrintWebformExporter:: |
public static | function |
Creates an instance of the plugin. Overrides WebformExporterBase:: |
|
WebformEntityPrintWebformExporter:: |
public | function |
Gets default configuration for this plugin. Overrides DocumentBaseWebformExporter:: |
|
WebformEntityPrintWebformExporter:: |
public | function |
Get the number of submissions to be exported with each batch. Overrides WebformExporterBase:: |
|
WebformEntityPrintWebformExporter:: |
protected | function | Get export type definition. | |
WebformEntityPrintWebformExporter:: |
protected | function | Get export type file extension. | |
WebformEntityPrintWebformExporter:: |
protected | function | Get export type id. | |
WebformEntityPrintWebformExporter:: |
public | function |
Write submission to export. Overrides WebformExporterBase:: |
|
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 |
Close export. Overrides WebformExporterInterface:: |
|
WebformExporterBase:: |
public | function |
Create export. Overrides WebformExporterInterface:: |
|
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 |
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 |
Open export. 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 |
WebformExporterInterface:: |
constant | Tar archive. | ||
WebformExporterInterface:: |
constant | ZIP file. |