public function WebformManagedFileBase::postSave in Webform 6.x
Same name and namespace in other branches
- 8.5 src/Plugin/WebformElement/WebformManagedFileBase.php \Drupal\webform\Plugin\WebformElement\WebformManagedFileBase::postSave()
Acts on a saved webform submission element before the insert or update hook is invoked.
Parameters
array $element: An element.
\Drupal\webform\WebformSubmissionInterface $webform_submission: A webform submission.
bool $update: TRUE if the entity has been updated, or FALSE if it has been inserted.
Overrides WebformElementBase::postSave
File
- src/
Plugin/ WebformElement/ WebformManagedFileBase.php, line 492
Class
- WebformManagedFileBase
- Provides a base class webform 'managed_file' elements.
Namespace
Drupal\webform\Plugin\WebformElementCode
public function postSave(array &$element, WebformSubmissionInterface $webform_submission, $update = TRUE) {
// Get current value and original value for this element.
$key = $element['#webform_key'];
$webform = $webform_submission
->getWebform();
if ($webform
->isResultsDisabled()) {
return;
}
$original_data = $webform_submission
->getOriginalData();
$data = $webform_submission
->getData();
$value = isset($data[$key]) ? $data[$key] : [];
$fids = is_array($value) ? $value : [
$value,
];
$original_value = isset($original_data[$key]) ? $original_data[$key] : [];
$original_fids = is_array($original_value) ? $original_value : [
$original_value,
];
// Delete the old file uploads.
$delete_fids = array_diff($original_fids, $fids);
static::deleteFiles($webform_submission, $delete_fids);
// Add new files.
$this
->addFiles($element, $webform_submission, $fids);
}