You are here

public function LicenseFileManager::getDownloadLimit in Commerce File 8.2

Gets the download limit for the given license.

Note that the logic both checks for the global limit and a limit configured at the product variation level (if overriden).

Parameters

\Drupal\commerce_license\Entity\LicenseInterface $license: The license entity.

Return value

int The download limit (0 for unlimited).

Overrides LicenseFileManagerInterface::getDownloadLimit

1 call to LicenseFileManager::getDownloadLimit()
LicenseFileManager::canDownload in src/LicenseFileManager.php
Gets whether the licensed file can be downloaded.

File

src/LicenseFileManager.php, line 171

Class

LicenseFileManager
Provides a service for managing licensed files.

Namespace

Drupal\commerce_file

Code

public function getDownloadLimit(LicenseInterface $license) {
  $download_limit = 0;

  // First, check whether a global limit is configured.
  $settings = $this->configFactory
    ->get('commerce_file.settings')
    ->get();
  if (!empty($settings['enable_download_limit'])) {
    $download_limit = $settings['download_limit'];
  }

  // Check the file download limit at the license level if specified.
  if ($license
    ->hasField('file_download_limit') && !$license
    ->get('file_download_limit')
    ->isEmpty()) {
    $download_limit = $license
      ->get('file_download_limit')->value;
  }
  return $download_limit;
}