protected function WebformSubmissionExportImportImporter::importEntityReferenceElement in Webform 6.x
Same name and namespace in other branches
- 8.5 modules/webform_submission_export_import/src/WebformSubmissionExportImportImporter.php \Drupal\webform_submission_export_import\WebformSubmissionExportImportImporter::importEntityReferenceElement()
Import entity reference element.
Parameters
array $element: A managed file element.
mixed $value: File URI(s) from CSV record.
\Drupal\webform\WebformSubmissionInterface|null $webform_submission: Existing submission or NULL if new submission.
array $errors: An array of error messages.
Return value
array|int|null An array of entity ids, a single entity id, or NULL if entity ids could not be imported.
1 call to WebformSubmissionExportImportImporter::importEntityReferenceElement()
- WebformSubmissionExportImportImporter::importElement in modules/
webform_submission_export_import/ src/ WebformSubmissionExportImportImporter.php - Import element.
File
- modules/
webform_submission_export_import/ src/ WebformSubmissionExportImportImporter.php, line 828
Class
- WebformSubmissionExportImportImporter
- Webform submission export importer.
Namespace
Drupal\webform_submission_export_importCode
protected function importEntityReferenceElement(array $element, $value, WebformSubmissionInterface $webform_submission = NULL, array &$errors) {
$element_plugin = $this->elementManager
->getElementInstance($element);
$entity_type_id = $element_plugin
->getTargetType($element);
$values = explode(',', $value);
foreach ($values as $index => $value) {
$values[$index] = $this
->getEntityImportId($entity_type_id, $value);
if ($values[$index] === NULL) {
$t_args = [
'@element_key' => $element['#webform_key'],
'@entity_id' => $value,
];
$errors[] = $this
->t('[@element_key] Unable to locate entity (@entity_id).', $t_args);
unset($values[$index]);
}
}
$values = array_values($values);
if (empty($values)) {
return $element_plugin
->hasMultipleValues($element) ? [] : NULL;
}
else {
return $element_plugin
->hasMultipleValues($element) ? $values : reset($values);
}
}