Assets ​
- Type
- Class
- Namespace
- craft\helpers
- Inherits
- craft\helpers\Assets
- Since
- 3.0.0
Class Assets
Public Methods ​
| Method | Description |
|---|---|
| fileTransferList() | Create an asset transfer list based on a list of assets and an array of changing folder IDs. |
| filename2Title() | Generates a default asset title based on its filename. |
| generateUrl() | Generates a URL for a given Assets file in a Source Type. |
| getAllowedFileKinds() | Returns a list of file kinds that are allowed to be uploaded. |
| getFileKindByExtension() | Return a file's kind by a file's extension. |
| getFileKindLabel() | Returns the label of a given file kind. |
| getFileKinds() | Returns a list of the supported file kinds. |
| getImageEditorSource() | Return an image path to use in the Image Editor for an asset by its ID and size. |
| getMaxUploadSize() | Returns the maximum allowed upload size in bytes per all config settings combined. |
| mirrorFolderStructure() | Mirrors a folder structure on a volume. |
| parseFileLocation() | Parses a file location in the format of {folder:X}filename.ext returns the folder ID + filename. |
| parseSrcsetSize() | Parses a srcset size (e.g. 100w or 2x). |
| periodList() | Get a list of available periods for Cache duration settings. |
| prepareAssetName() | Clean an Asset's filename. |
| scaledDimensions() | Returns scaled width & height values for a maximum container size. |
| sortFolderTree() | Sorts a folder tree by the volume sort order. |
| tempFilePath() | Get a temporary file path. |
| urlAppendix() | Get appendix for a URL based on its Source caching settings. |
fileTransferList() ​
Create an asset transfer list based on a list of assets and an array of changing folder IDs.
Arguments ​
Returns ​
filename2Title() ​
Generates a default asset title based on its filename.
Arguments ​
$filename(string) – The asset's filename
Returns ​
generateUrl() ​
Generates a URL for a given Assets file in a Source Type.
Arguments ​
$volume(craft\base\VolumeInterface)$asset(craft\elements\Asset)$uri(string, null) – Asset URI to use. Defaults to the filename.$transformIndex(craft\models\AssetTransformIndex, null) – Transform index, for which the URL is being generated, if any
Returns ​
getAllowedFileKinds() ​
- Since
- 3.1.16
Returns a list of file kinds that are allowed to be uploaded.
Returns ​
array – The allowed file kinds
getFileKindByExtension() ​
Return a file's kind by a file's extension.
Arguments ​
$file(string) – The file name/path
Returns ​
string – The file kind, or "unknown" if unknown.
getFileKindLabel() ​
Returns the label of a given file kind.
Arguments ​
$kind(string)
Returns ​
getFileKinds() ​
Returns a list of the supported file kinds.
Returns ​
array – The supported file kinds
getImageEditorSource() ​
Return an image path to use in the Image Editor for an asset by its ID and size.
Arguments ​
Returns ​
Throws ​
- yii\base\Exception
in case of failure
getMaxUploadSize() ​
Returns the maximum allowed upload size in bytes per all config settings combined.
Returns ​
mirrorFolderStructure() ​
Mirrors a folder structure on a volume.
Arguments ​
$sourceParentFolder(craft\models\VolumeFolder) – Folder who's children folder structure should be mirrored.$destinationFolder(craft\models\VolumeFolder) – The destination folder$targetTreeMap(array) – Map of relative path => existing folder ID
Returns ​
array – Map of original folder ID => new folder ID
parseFileLocation() ​
Parses a file location in the format of {folder:X}filename.ext returns the folder ID + filename.
Arguments ​
$location(string)
Returns ​
Throws ​
- yii\base\Exception
if the file location is invalid
parseSrcsetSize() ​
- Since
- 3.5.0
Parses a srcset size (e.g. 100w or 2x).
Arguments ​
$size(mixed)
Returns ​
array – An array of the size value and unit (w or x)
Throws ​
- yii\base\InvalidArgumentException
if the size can’t be parsed
periodList() ​
Get a list of available periods for Cache duration settings.
Returns ​
prepareAssetName() ​
Clean an Asset's filename.
Arguments ​
$name(string)$isFilename(boolean) – If set to true (default), will separate extension and clean the filename separately.$preventPluginModifications(boolean) – If set to true, will prevent plugins from modify
Returns ​
scaledDimensions() ​
- Since
- 3.4.21
Returns scaled width & height values for a maximum container size.
Arguments ​
Returns ​
array – The scaled width and height
sortFolderTree() ​
DEPRECATED
Deprecated in 3.8.0
Sorts a folder tree by the volume sort order.
Arguments ​
$tree(craft\models\VolumeFolder[]) – Array passed by reference of the sortable folders.
tempFilePath() ​
Get a temporary file path.
Arguments ​
$extension(string) – Extension to use. "tmp" by default.
Returns ​
string – The temporary file path
Throws ​
- yii\base\Exception
in case of failure
urlAppendix() ​
Get appendix for a URL based on its Source caching settings.
Arguments ​
$volume(craft\base\VolumeInterface)$asset(craft\elements\Asset)$transformIndex(craft\models\AssetTransformIndex, null) – Transform index, for which the URL is being generated, if any
Returns ​
Constants ​
| Constant | Description |
|---|---|
INDEX_SKIP_ITEMS_PATTERN |
Events ​
EVENT_REGISTER_FILE_KINDS ​
The event that is triggered when registering asset file kinds.
EVENT_SET_FILENAME ​
The event that is triggered when defining an asset’s filename.