protected function VboExportBase::sendToFile in VBO export 8.2
Same name and namespace in other branches
- 8.3 src/Plugin/Action/VboExportBase.php \Drupal\vbo_export\Plugin\Action\VboExportBase::sendToFile()
- 8 src/Plugin/Action/VboExportBase.php \Drupal\vbo_export\Plugin\Action\VboExportBase::sendToFile()
Output generated string to file. Message user.
Parameters
string $output: The string that will be saved to a file.
1 call to VboExportBase::sendToFile()
- VboExportBase::executeMultiple in src/
Plugin/ Action/ VboExportBase.php - Execute multiple handler.
File
- src/
Plugin/ Action/ VboExportBase.php, line 79
Class
- VboExportBase
- Base class for export actions.
Namespace
Drupal\vbo_export\Plugin\ActionCode
protected function sendToFile($output) {
if (!empty($output)) {
$rand = substr(hash('ripemd160', uniqid()), 0, 8);
$filename = $this->context['view_id'] . '_' . date('Y_m_d_H_i', REQUEST_TIME) . '-' . $rand . '.' . static::EXTENSION;
$wrappers = $this->streamWrapperManager
->getWrappers();
if (isset($wrappers['private'])) {
$wrapper = 'private';
}
else {
$wrapper = 'public';
}
$destination = $wrapper . '://' . $filename;
$file = file_save_data($output, $destination, FILE_EXISTS_REPLACE);
$file
->setTemporary();
$file
->save();
$file_url = Url::fromUri(file_create_url($file
->getFileUri()));
$link = Link::fromTextAndUrl($this
->t('Click here'), $file_url);
drupal_set_message($this
->t('Export file created, @link to download.', array(
'@link' => $link
->toString(),
)));
}
}