protected function VboExportBase::sendToFile in VBO export 8
Same name and namespace in other branches
- 8.3 src/Plugin/Action/VboExportBase.php \Drupal\vbo_export\Plugin\Action\VboExportBase::sendToFile()
- 8.2 src/Plugin/Action/VboExportBase.php \Drupal\vbo_export\Plugin\Action\VboExportBase::sendToFile()
Output generated string to file. Message user.
1 call to VboExportBase::sendToFile()
- VboExportBase::executeMultiple in src/
Plugin/ Action/ VboExportBase.php - Execute multiple handler.
File
- src/
Plugin/ Action/ VboExportBase.php, line 20
Class
- VboExportBase
- Base class for export actions.
Namespace
Drupal\vbo_export\Plugin\ActionCode
protected function sendToFile($csv_string, $filename) {
$stream_wrapper_manager = \Drupal::service('stream_wrapper_manager');
$wrappers = $stream_wrapper_manager
->getWrappers();
if (isset($wrappers['private'])) {
$wrapper = 'private';
}
else {
$wrapper = 'public';
}
if (!empty($csv_string)) {
$destination = $wrapper . '://' . $filename;
$file = file_save_data($csv_string, $destination, FILE_EXISTS_REPLACE);
$file
->setTemporary();
$file
->save();
$file_url = Url::fromUri(file_create_url($file
->getFileUri()));
$link = \Drupal::l(t('Click here'), $file_url);
drupal_set_message(t('Export file created, @link to download.', array(
'@link' => $link,
)));
}
}