Assets

Type
Class
Namespace
craft\helpers
Inherits
craft\helpers\Assets
Since
3.0

Class Assets

View source

Public Methods

MethodDescription
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()Generate a URL for a given Assets file in a Source Type.
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.
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.
periodList()Get a list of available periods for Cache duration settings.
prepareAssetName()Clean an Asset's filename.
sortFolderTree()Sorts a folder tree by Volume sort order.
tempFilePath()Get a temporary file path.
urlAppendix()Get appendix for an URL based on it's Source caching settings.

fileTransferList()

Create an Asset transfer list based on a list of Assets and an array of changing folder ids.

View source

Arguments

  • $assets (array) – List of assets
  • $folderIdChanges (array) – A map of folder id changes

Returns

array

Signature

public static array fileTransferList ( array $assets, array $folderIdChanges )

filename2Title()

Generates a default asset title based on its filename.

View source

Arguments

  • $filename (string) – The asset's filename

Returns

string

Signature

public static string filename2Title ( \craft\helpers\string $filename )

generateUrl()

Generate a URL for a given Assets file in a Source Type.

View source

Arguments

Returns

string

Signature

public static string generateUrl ( craft\base\VolumeInterface $volume, craft\elements\Asset $file )

getFileKindByExtension()

Return a file's kind by a file's extension.

View source

Arguments

  • $file (string) – The file name/path

Returns

string – The file kind, or "unknown" if unknown.

Signature

public static string getFileKindByExtension ( \craft\helpers\string $file )

getFileKindLabel()

Returns the label of a given file kind.

View source

Arguments

Returns

string

Signature

public static string getFileKindLabel ( \craft\helpers\string $kind )

getFileKinds()

Returns a list of the supported file kinds.

View source

Returns

array – The supported file kinds

Signature

public static array getFileKinds ( )

getImageEditorSource()

Return an image path to use in Image Editor for an Asset by id and size.

View source

Arguments

Returns

false, string

Throws

Signature

public static false, string getImageEditorSource ( \craft\helpers\int $assetId, \craft\helpers\int $size )

getMaxUploadSize()

Returns the maximum allowed upload size in bytes per all config settings combined.

View source

Returns

integer, float

Signature

public static integer, float getMaxUploadSize ( )

mirrorFolderStructure()

Mirror a folder structure on a Volume.

View source

Arguments

Returns

array – Map of original folder id => new folder id

Signature

public static array mirrorFolderStructure ( craft\models\VolumeFolder $sourceParentFolder, craft\models\VolumeFolder $destinationFolder, array $targetTreeMap = [] )

parseFileLocation()

Parses a file location in the format of {folder:X}filename.ext returns the folder ID + filename.

View source

Arguments

Returns

array

Throws

Signature

public static array parseFileLocation ( $location )

periodList()

Get a list of available periods for Cache duration settings.

View source

Returns

array

Signature

public static array periodList ( )

prepareAssetName()

Clean an Asset's filename.

View source

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

string

Signature

public static string prepareAssetName ( \craft\helpers\string $name, \craft\helpers\bool $isFilename = true, \craft\helpers\bool $preventPluginModifications = false )

sortFolderTree()

Sorts a folder tree by Volume sort order.

View source

Arguments

  • $tree

Signature

public static void sortFolderTree ( array &$tree )

tempFilePath()

Get a temporary file path.

View source

Arguments

  • $extension (string) – Extension to use. "tmp" by default.

Returns

string – The temporary file path

Throws

Signature

public static string tempFilePath ( \craft\helpers\string $extension = 'tmp' )

urlAppendix()

Get appendix for an URL based on it's Source caching settings.

View source

Arguments

Returns

string

Signature

public static string urlAppendix ( craft\base\VolumeInterface $volume, craft\elements\Asset $file )

Constants

ConstantDescription
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.