class AssetService (View source)

An asset service that handles for example commands on assets, retrieves information about usage of assets and rendering thumbnails.

Properties

protected ResourceManager $resourceManager
protected ThumbnailService $thumbnailService
protected UriBuilder $uriBuilder
protected ObjectManagerInterface $objectManager
protected ReflectionService $reflectionService
protected array $usageStrategies
protected PackageManager $packageManager
protected LoggerInterface $logger
protected ImageService $imageService
protected AssetVariantGenerator $assetVariantGenerator

Methods

RepositoryInterface
getRepository(AssetInterface $asset)

Returns the repository for an asset

array|null
getThumbnailUriAndSizeForAsset(AssetInterface $asset, ThumbnailConfiguration $configuration, ActionRequest $request = null)

Calculates the dimensions of the thumbnail to be generated and returns the thumbnail URI.

array
getUsageStrategies()

Returns all registered asset usage strategies

array
getUsageReferences(AssetInterface $asset)

Returns an array of asset usage references.

int
getUsageCount(AssetInterface $asset)

Returns the total count of times an asset is used.

bool
isInUse(AssetInterface $asset)

Returns true if the asset is used.

void
validateRemoval(AssetInterface $asset)

Validates if the asset can be removed

void
replaceAssetResource(AssetInterface $asset, PersistentResource $resource, array $options = [])

Replace resource on an asset. Takes variants and redirect handling into account.

void
emitAssetCreated(AssetInterface $asset)

Signals that an asset was added.

void
emitAssetRemoved(AssetInterface $asset)

Signals that an asset was removed.

void
emitAssetUpdated(AssetInterface $asset)

Signals that an asset was updated.

void
emitAssetResourceReplaced(AssetInterface $asset)

Signals that a resource on an asset has been replaced

Details

RepositoryInterface getRepository(AssetInterface $asset)

Returns the repository for an asset

Parameters

AssetInterface $asset

Return Value

RepositoryInterface

array|null getThumbnailUriAndSizeForAsset(AssetInterface $asset, ThumbnailConfiguration $configuration, ActionRequest $request = null)

Calculates the dimensions of the thumbnail to be generated and returns the thumbnail URI.

In case of Images this is a thumbnail of the image, in case of other assets an icon representation.

Parameters

AssetInterface $asset
ThumbnailConfiguration $configuration
ActionRequest $request

Request argument must be provided for asynchronous thumbnails

Return Value

array|null

Array with keys "width", "height" and "src" if the thumbnail generation work or null

Exceptions

AssetServiceException
ThumbnailServiceException
MissingActionNameException
Exception

protected array getUsageStrategies()

Returns all registered asset usage strategies

Return Value

array

array getUsageReferences(AssetInterface $asset)

Returns an array of asset usage references.

Parameters

AssetInterface $asset

Return Value

array

int getUsageCount(AssetInterface $asset)

Returns the total count of times an asset is used.

Parameters

AssetInterface $asset

Return Value

int

bool isInUse(AssetInterface $asset)

Returns true if the asset is used.

Parameters

AssetInterface $asset

Return Value

bool

void validateRemoval(AssetInterface $asset)

Validates if the asset can be removed

Parameters

AssetInterface $asset

Return Value

void

Exceptions

AssetServiceException

Thrown if the asset can not be removed

void replaceAssetResource(AssetInterface $asset, PersistentResource $resource, array $options = [])

Replace resource on an asset. Takes variants and redirect handling into account.

Parameters

AssetInterface $asset
PersistentResource $resource
array $options

Return Value

void

void emitAssetCreated(AssetInterface $asset)

Signals that an asset was added.

Parameters

AssetInterface $asset

Return Value

void

void emitAssetRemoved(AssetInterface $asset)

Signals that an asset was removed.

Parameters

AssetInterface $asset

Return Value

void

void emitAssetUpdated(AssetInterface $asset)

Signals that an asset was updated.

Parameters

AssetInterface $asset

Return Value

void

void emitAssetResourceReplaced(AssetInterface $asset)

Signals that a resource on an asset has been replaced

Note: when an asset resource is replaced, the assetUpdated signal is sent anyway and can be used instead.

Parameters

AssetInterface $asset

Return Value

void