public function WebformEntityStorage::delete in Webform 8.5
Same name and namespace in other branches
- 6.x src/WebformEntityStorage.php \Drupal\webform\WebformEntityStorage::delete()
Deletes permanently saved entities.
Parameters
array $entities: An array of entity objects to delete.
Throws
\Drupal\Core\Entity\EntityStorageException In case of failures, an exception is thrown.
Overrides EntityStorageBase::delete
File
- src/
WebformEntityStorage.php, line 149
Class
- WebformEntityStorage
- Storage controller class for "webform" configuration entities.
Namespace
Drupal\webformCode
public function delete(array $entities) {
parent::delete($entities);
if (!$entities) {
// If no entities were passed, do nothing.
return;
}
// Delete all webform submission log entries.
$webform_ids = [];
foreach ($entities as $entity) {
$webform_ids[] = $entity
->id();
}
// Delete all webform records used to track next serial.
$this->database
->delete('webform')
->condition('webform_id', $webform_ids, 'IN')
->execute();
// Remove the webform specific file directory for all stream wrappers.
// @see \Drupal\webform\Plugin\WebformElement\WebformManagedFileBase
// @see \Drupal\webform\Plugin\WebformElement\WebformSignature
foreach ($entities as $entity) {
$stream_wrappers = array_keys(\Drupal::service('stream_wrapper_manager')
->getNames(StreamWrapperInterface::WRITE_VISIBLE));
foreach ($stream_wrappers as $stream_wrapper) {
$file_directory = $stream_wrapper . '://webform/' . $entity
->id();
if (file_exists($file_directory)) {
// Clear all signature files.
// @see \Drupal\webform\Plugin\WebformElement\WebformSignature::getImageUrl
$files = $this->fileSystem
->scanDirectory($file_directory, '/^signature-.*/');
foreach (array_keys($files) as $uri) {
$this->fileSystem
->delete($uri);
}
// Clear empty webform directory.
if (empty($this->fileSystem
->scanDirectory($file_directory, '/.*/'))) {
$this->fileSystem
->deleteRecursive($file_directory);
}
}
}
}
}