You are here

public function LicenseFileManager::isLicensable in Commerce File 8.2

Gets whether the given file is licensable.

Parameters

\Drupal\file\FileInterface $file: The file.

Return value

bool Whether the given file is licensable.

Overrides LicenseFileManagerInterface::isLicensable

File

src/LicenseFileManager.php, line 190

Class

LicenseFileManager
Provides a service for managing licensed files.

Namespace

Drupal\commerce_file

Code

public function isLicensable(FileInterface $file) {
  if (isset($this->isLicensable[$file
    ->id()])) {
    return $this->isLicensable[$file
      ->id()];
  }

  /** @var \Drupal\commerce_product\ProductVariationStorageInterface $product_variation_storage */
  $product_variation_storage = $this->entityTypeManager
    ->getStorage('commerce_product_variation');
  $query = $product_variation_storage
    ->getQuery()
    ->accessCheck(FALSE)
    ->condition('commerce_file.target_id', $file
    ->id())
    ->count();
  $this->isLicensable[$file
    ->id()] = (bool) $query
    ->execute() > 0;
  return $this->isLicensable[$file
    ->id()];
}