You are here

class ArchiveDownloader in Content Synchronizer 8

Same name and namespace in other branches
  1. 8.2 src/Service/ArchiveDownloader.php \Drupal\content_synchronizer\Service\ArchiveDownloader
  2. 3.x src/Service/ArchiveDownloader.php \Drupal\content_synchronizer\Service\ArchiveDownloader

Class ArchiveDownloader.

@package Drupal\content_synchronizer\Service

Hierarchy

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'
content_synchronizer.services.yml in ./content_synchronizer.services.yml
content_synchronizer.services.yml
1 service uses ArchiveDownloader
content_synchronizer.archive_downloader in ./content_synchronizer.services.yml
\Drupal\content_synchronizer\Service\ArchiveDownloader

File

src/Service/ArchiveDownloader.php, line 14

Namespace

Drupal\content_synchronizer\Service
View 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

Namesort descending Modifiers Type Description Overrides
ArchiveDownloader::ARCHIVE_PARAMS constant
ArchiveDownloader::canDownload public function Return true if the current page is admin.
ArchiveDownloader::donwloadArchive public function Donwload archive by adding js library.
ArchiveDownloader::redirectWithArchivePath public function Redirect to the page with download.
ArchiveDownloader::SERVICE_NAME constant