A package to provide selection of whole asset collection and tags in Neos content editing that keeps caching in mind.
The CodeQ.Asset EelHelper provides utility methods for working with assets, asset collections, and tags in Neos CMS. It is designed to be used in Eel expressions and supports various operations such as retrieving assets by collection or tag, sorting assets, and converting file sizes to human-readable formats.
Retrieves an AssetCollection by its identifier.
- Parameters:
string $identifier: The identifier of the asset collection.
- Returns: The
AssetCollectionobject if found, ornullif not.
Retrieves a Tag by its identifier.
- Parameters:
string $identifier: The identifier of the tag.
- Returns: The
Tagobject if found, ornullif not.
Retrieves assets from a given collection, optionally filtered by type.
- Parameters:
mixed $collection: The collection identifier or anAssetCollectionobject.string\|null $type: The type of assets to retrieve (`'image'` for images, or `null` for all assets).
- Returns: An array of assets in the collection, sorted by title or filename.
- Throws:
InvalidArgumentExceptionif an invalid type is provided.InvalidQueryExceptionif the query fails.
Retrieves assets associated with a given tag, optionally filtered by type.
- Parameters:
mixed $tag: The tag identifier or aTagobject.string\|null $type: The type of assets to retrieve (`'image'` for images, or `null` for all assets).
- Returns: An array of assets associated with the tag, sorted by title or filename.
- Throws:
InvalidArgumentExceptionif an invalid type is provided.InvalidQueryExceptionif the query fails.
Converts a file size in bytes to a human-readable format.
- Parameters:
int $size: The file size in bytes.
- Returns: A string representing the file size in a human-readable format (e.g., `1.2 MB`, `512 KB`).
You can use the CodeQ.Asset EelHelper in your Fusion code as follows:
prototype(Your.Package:Component) {
assets = ${CodeQ.Asset.getAssetsByCollection('your-collection-identifier')}
humanReadableSize = ${CodeQ.Asset.humanReadableFileSize(1048576)} # Outputs "1.0 MB"
}
- The methods are designed to handle both identifiers and object instances for collections and tags.
The CodeQ.AssetCacheTag EelHelper provides utility methods for generating cache tags for assets, asset collections, and tags in Neos CMS. These methods are designed to be used in Eel expressions and help manage caching effectively.
Generates cache tags for a given asset or an array of assets.
- Parameters:
array|Asset $assets: A singleAssetobject or an array ofAssetobjects.
- Returns: An array of cache tags for the provided assets.
Generates a cache tag for a given asset collection.
- Parameters:
AssetCollection $assetCollection: The asset collection for which the cache tag is generated.
- Returns: A string representing the cache tag for the asset collection.
Generates cache tags for a given tag or an array of tags.
- Parameters:
array|Tag $tags: A singleTagobject or an array ofTagobjects.
- Returns: An array of cache tags for the provided tags.
You can use the CodeQ.AssetCacheTag EelHelper in your Fusion code as follows:
prototype(Your.Package:Component) {
@cache {
entryTags {
0 = ${CodeQ.AssetCacheTag.assetTag(asset)}
1 = ${CodeQ.AssetCacheTag.assetCollectionTag(assetCollection)}
2 = ${CodeQ.AssetCacheTag.assetTagsCachingTag(tags)}
}
}
}