Assets
- Type
- Class
- Namespace
- craft\helpers
- Inherits
- craft\helpers\Assets
- Since
- 3.0.0
Class Assets
View source (opens new window)
# Public Methods
Method | Description |
---|---|
downloadFile() | Save a file from a filesystem locally. |
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 the URL for an asset. |
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. |
iconPath() | Returns the file path to an asset icon for a given extension. |
iconSvg() | Returns the SVG contents for an asset icon with a given extension. |
iconUrl() | Returns the URL to an asset icon for a given extension. |
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. |
revParams() | Returns revision query parameters that should be appended to as asset URL. |
revUrl() | Appends revision parameters to a URL. |
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. |
# downloadFile()
- Since
- 4.0.0
Save a file from a filesystem locally.
View source (opens new window)
Arguments
$fs
(craft\base\BaseFsInterface)$uriPath
(string (opens new window))$localPath
(string (opens new window))
Returns
Throws
# fileTransferList()
Create an asset transfer list based on a list of assets and an array of changing folder IDs.
View source (opens new window)
Arguments
$assets
(array (opens new window)) – List of assets$folderIdChanges
(array (opens new window)) – A map of folder ID changes
Returns
# filename2Title()
Generates a default asset title based on its filename.
View source (opens new window)
Arguments
$filename
(string (opens new window)) – The asset's filename
Returns
# generateUrl()
Generates the URL for an asset.
View source (opens new window)
Arguments
$fs
(craft\base\BaseFsInterface)$asset
(craft\elements\Asset)$uri
(string (opens new window), null (opens new window)) – Asset URI to use. Defaults to the filename.$dateUpdated
(DateTime (opens new window), null (opens new window)) – Last datetime the target of the url was updated, if known
Returns
Throws
- yii\base\InvalidConfigException (opens new window)
if the asset doesn’t have a filename.
# getAllowedFileKinds()
- Since
- 3.1.16
Returns a list of file kinds that are allowed to be uploaded.
View source (opens new window)
Returns
array (opens new window) – The allowed file kinds
# getFileKindByExtension()
Return a file's kind by a file's extension.
View source (opens new window)
Arguments
$file
(string (opens new window)) – The file name/path
Returns
string (opens new window) – The file kind, or "unknown" if unknown.
# getFileKindLabel()
Returns the label of a given file kind.
View source (opens new window)
Arguments
$kind
(string (opens new window))
Returns
# getFileKinds()
Returns a list of the supported file kinds.
View source (opens new window)
Returns
array (opens new window) – The supported file kinds
# getImageEditorSource()
Return an image path to use in the Image Editor for an asset by its ID and size.
View source (opens new window)
Arguments
$assetId
(integer (opens new window))$size
(integer (opens new window))
Returns
string (opens new window), false (opens new window)
Throws
- yii\base\Exception (opens new window)
in case of failure
# getMaxUploadSize()
Returns the maximum allowed upload size in bytes per all config settings combined.
View source (opens new window)
Returns
integer (opens new window), float (opens new window)
# iconPath()
DEPRECATED
Deprecated in 4.5.0. iconSvg() or Asset::getThumbSvg()
should be used instead.
- Since
- 4.0.0
Returns the file path to an asset icon for a given extension.
View source (opens new window)
Arguments
$extension
(string (opens new window))
Returns
# iconSvg()
- Since
- 4.5.0
Returns the SVG contents for an asset icon with a given extension.
View source (opens new window)
Arguments
$extension
(string (opens new window))
Returns
# iconUrl()
DEPRECATED
Deprecated in 4.5.0
- Since
- 4.0.0
Returns the URL to an asset icon for a given extension.
View source (opens new window)
Arguments
$extension
(string (opens new window))
Returns
# mirrorFolderStructure()
Mirrors a folder structure on a volume.
View source (opens new window)
Arguments
$sourceParentFolder
(craft\models\VolumeFolder) – Folder who's children folder structure should be mirrored.$destinationFolder
(craft\models\VolumeFolder) – The destination folder$targetTreeMap
(array (opens new window)) – Map of relative path => existing folder ID
Returns
array (opens new window) – 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.
View source (opens new window)
Arguments
$location
(string (opens new window))
Returns
Throws
- yii\base\InvalidArgumentException (opens new window)
if the file location is invalid
# parseSrcsetSize()
- Since
- 3.5.0
Parses a srcset size (e.g. 100w
or 2x
).
View source (opens new window)
Arguments
$size
(mixed
)
Returns
array (opens new window) – An array of the size value and unit (w
or x
)
Throws
- yii\base\InvalidArgumentException (opens new window)
if the size can’t be parsed
# periodList()
Get a list of available periods for Cache duration settings.
View source (opens new window)
Returns
# prepareAssetName()
Clean an Asset's filename.
View source (opens new window)
Arguments
$name
(string (opens new window))$isFilename
(boolean (opens new window)) – If set to true (default), will separate extension and clean the filename separately.$preventPluginModifications
(boolean (opens new window)) – If set to true, will prevent plugins from modify
Returns
# revParams()
- Since
- 4.0.0
Returns revision query parameters that should be appended to as asset URL.
View source (opens new window)
Arguments
$asset
(craft\elements\Asset)$dateUpdated
(DateTime (opens new window), null (opens new window))
Returns
# revUrl()
- Since
- 4.3.7
Appends revision parameters to a URL.
View source (opens new window)
Arguments
$url
(string (opens new window))$asset
(craft\elements\Asset)$dateUpdated
(DateTime (opens new window), null (opens new window))$fsOnly
(boolean (opens new window)) – Only append a revision param if the URL begins with the asset’s filesystem URL
Returns
# scaledDimensions()
- Since
- 3.4.21
Returns scaled width & height values for a maximum container size.
View source (opens new window)
Arguments
$realWidth
(integer (opens new window))$realHeight
(integer (opens new window))$maxWidth
(integer (opens new window))$maxHeight
(integer (opens new window))
Returns
array (opens new window) – The scaled width and height
# sortFolderTree()
DEPRECATED
Deprecated in 4.4.0
Sorts a folder tree by the volume sort order.
View source (opens new window)
Arguments
$tree
(craft\models\VolumeFolder[]) – Array passed by reference of the sortable folders.
# tempFilePath()
Get a temporary file path.
View source (opens new window)
Arguments
$extension
(string (opens new window)) – Extension to use. "tmp" by default.
Returns
string (opens new window) – The temporary file path
Throws
- yii\base\Exception (opens new window)
in case of failure
# urlAppendix()
DEPRECATED
Deprecated in 4.0.0. generateUrl() should be used instead.
Get appendix for a URL based on its Source caching settings.
View source (opens new window)
Arguments
$asset
(craft\elements\Asset)$dateUpdated
(DateTime (opens new window), null (opens new window)) – Last datetime the target of the url was updated, if known
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.