class ArchiveDownloader in Content Synchronizer 8
Same name and namespace in other branches
- 8.2 src/Service/ArchiveDownloader.php \Drupal\content_synchronizer\Service\ArchiveDownloader
- 3.x src/Service/ArchiveDownloader.php \Drupal\content_synchronizer\Service\ArchiveDownloader
Class ArchiveDownloader.
@package Drupal\content_synchronizer\Service
Hierarchy
- class \Drupal\content_synchronizer\Service\ArchiveDownloader
Expanded class hierarchy of ArchiveDownloader
5 files declare their use of ArchiveDownloader
- ArchiveDownloaderController.php in src/
Controller/ ArchiveDownloaderController.php - content_synchronizer.module in ./
content_synchronizer.module - Hooks definitions for content_synchronizer module.
- ExportConfirmForm.php in src/
Form/ ExportConfirmForm.php - LaunchExportForm.php in src/
Form/ LaunchExportForm.php - QuickExportController.php in src/
Controller/ QuickExportController.php
1 string reference to 'ArchiveDownloader'
1 service uses ArchiveDownloader
File
- src/
Service/ ArchiveDownloader.php, line 14
Namespace
Drupal\content_synchronizer\ServiceView source
class ArchiveDownloader {
const SERVICE_NAME = 'content_synchronizer.archive_downloader';
const ARCHIVE_PARAMS = 'cs_archive';
/**
* Donwload archive by adding js library.
*
* @param array $vars
* Preprocess data.
*/
public function donwloadArchive(array &$vars) {
if ($this
->canDownload()) {
$vars['#attached']['library'][] = 'content_synchronizer/download_archive';
}
}
/**
* Return true if the current page is admin.
*
* @see https://drupal.stackexchange.com/questions/219370/how-to-test-if-current-page-is-an-admin-page
*
* @return bool
*/
public function canDownload() {
$account = \Drupal::currentUser();
return \Drupal\user\Entity\User::load($account
->id())
->hasPermission('add export entity entities');
}
/**
* Redirect to the page with download.
*
* @param string $redirectUrl
* The url.
* @param string $archiveUri
* The archiev url.
*/
public function redirectWithArchivePath($redirectUrl, $archiveUri) {
$path = str_replace(ExportEntityWriter::GENERATOR_DIR, '', $archiveUri);
$redirectUrl .= "#" . static::ARCHIVE_PARAMS . '=' . urlencode($path);
$redirect = new RedirectResponse($redirectUrl);
$redirect
->send();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ArchiveDownloader:: |
constant | |||
ArchiveDownloader:: |
public | function | Return true if the current page is admin. | |
ArchiveDownloader:: |
public | function | Donwload archive by adding js library. | |
ArchiveDownloader:: |
public | function | Redirect to the page with download. | |
ArchiveDownloader:: |
constant |