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 a URL for a given Assets file on a filesystem.
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 Image Editor for an Asset by 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.
iconUrl() Returns the URL to an asset icon for a given extension.
mirrorFolderStructure() Mirror 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() Revisions the query parameters that should be appended to asset URLs, per the revAssetUrls config setting.
scaledDimensions() Returns scaled width & height values for a maximum container size.
sortFolderTree() Sorts a folder tree by 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

Returns

integer (opens new window)

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

Returns

array (opens new window)

# filename2Title()

Generates a default asset title based on its filename.

View source (opens new window)

Arguments

Returns

string (opens new window)

# generateUrl()

Generates a URL for a given Assets file on a filesystem.

View source (opens new window)

Arguments

Returns

string (opens new window)

Throws

# 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

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

Returns

string (opens new window)

# 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 Image Editor for an Asset by id and size.

View source (opens new window)

Arguments

Returns

string (opens new window), false (opens new window)

Throws

# 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()

Since
4.0.0

Returns the file path to an asset icon for a given extension.

View source (opens new window)

Arguments

Returns

string (opens new window)

# iconUrl()

Since
4.0.0

Returns the URL to an asset icon for a given extension.

View source (opens new window)

Arguments

Returns

string (opens new window)

# mirrorFolderStructure()

Mirror a folder structure on a Volume.

View source (opens new window)

Arguments

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

Returns

array (opens new window)

Throws

# 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

# periodList()

Get a list of available periods for Cache duration settings.

View source (opens new window)

Returns

array (opens new window)

# prepareAssetName()

Clean an Asset's filename.

View source (opens new window)

Arguments

Returns

string (opens new window)

# revParams()

Since
4.0.0

Revisions the query parameters that should be appended to asset URLs, per the revAssetUrls config setting.

View source (opens new window)

Arguments

Returns

array (opens new window)

# scaledDimensions()

Since
3.4.21

Returns scaled width & height values for a maximum container size.

View source (opens new window)

Arguments

Returns

array (opens new window) – The scaled width and height

# sortFolderTree()

Sorts a folder tree by Volume sort order.

View source (opens new window)

Arguments

# tempFilePath()

Get a temporary file path.

View source (opens new window)

Arguments

Returns

string (opens new window) – The temporary file path

Throws

# 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

Returns

string (opens new window)

# Constants

Constant Description
INDEX_SKIP_ITEMS_PATTERN

# Events

# EVENT_REGISTER_FILE_KINDS

Type
craft\events\RegisterAssetFileKindsEvent

The event that is triggered when registering asset file kinds.

# EVENT_SET_FILENAME

Type
craft\helpers\SetElementTableAttributeHtmlEvent

The event that is triggered when defining an asset’s filename.