public function WebformCliService::drush_webform_import in Webform 6.x
Same name and namespace in other branches
- 8.5 src/Commands/WebformCliService.php \Drupal\webform\Commands\WebformCliService::drush_webform_import()
File
- src/
Commands/ WebformCliService.php, line 411
Class
- WebformCliService
- Drush version agnostic commands.
Namespace
Drupal\webform\CommandsCode
public function drush_webform_import($webform_id = NULL, $import_uri = NULL) {
/** @var \Drupal\webform_submission_export_import\WebformSubmissionExportImportImporterInterface $submission_importer */
$submission_importer = \Drupal::service('webform_submission_export_import.importer');
// Get webform.
$webform = Webform::load($webform_id);
// Get source entity.
$entity_type = $this
->drush_get_option('entity-type');
$entity_id = $this
->drush_get_option('entity-id');
if ($entity_type && $entity_id) {
$source_entity = \Drupal::entityTypeManager()
->getStorage($entity_type)
->load($entity_id);
}
else {
$source_entity = NULL;
}
// Get import options
$import_options = $this
->_drush_get_options($submission_importer
->getDefaultImportOptions());
$submission_importer
->setWebform($webform);
$submission_importer
->setSourceEntity($source_entity);
$submission_importer
->setImportOptions($import_options);
$submission_importer
->setImportUri($import_uri);
$t_args = [
'@total' => $submission_importer
->getTotal(),
];
if (!$this
->drush_confirm($this
->dt('Are you sure you want to import @total submissions?', $t_args) . PHP_EOL . $this
->dt('This action cannot be undone.'))) {
return $this
->drush_user_abort();
}
WebformSubmissionExportImportUploadForm::batchSet($webform, $source_entity, $import_uri, $import_options);
$this
->drush_backend_batch_process();
return NULL;
}