Class craft\helpers\Assets
- Inheritance
- craft\helpers\Assets
- Available since version
- 3.0
- Source Code
- https://github.com/craftcms/cms/blob/master/src/helpers/Assets.php
Class Assets
Method | Description | Defined By |
---|---|---|
fileTransferList() |
Create an Asset transfer list based on a list of Assets and an array of changing folder ids. | craft\helpers\Assets |
filename2Title() |
Generates a default asset title based on its filename. | craft\helpers\Assets |
generateUrl() |
Generate a URL for a given Assets file in a Source Type. | craft\helpers\Assets |
getFileKindByExtension() |
Return a file's kind by a file's extension. | craft\helpers\Assets |
getFileKindLabel() |
Returns the label of a given file kind. | craft\helpers\Assets |
getFileKinds() |
Returns a list of the supported file kinds. | craft\helpers\Assets |
getImageEditorSource() |
Return an image path to use in Image Editor for an Asset by id and size. | craft\helpers\Assets |
mirrorFolderStructure() |
Mirror a folder structure on a Volume. | craft\helpers\Assets |
parseFileLocation() |
Parses a file location in the format of {folder:X}filename.ext returns the folder ID + filename. |
craft\helpers\Assets |
periodList() |
Get a list of available periods for Cache duration settings. | craft\helpers\Assets |
prepareAssetName() |
Clean an Asset's filename. | craft\helpers\Assets |
sortFolderTree() |
Sorts a folder tree by Volume sort order. | craft\helpers\Assets |
tempFilePath() |
Get a temporary file path. | craft\helpers\Assets |
urlAppendix() |
Get appendix for an URL based on it's Source caching settings. | craft\helpers\Assets |
Event | Type | Description | Defined By |
---|---|---|---|
EVENT_REGISTER_FILE_KINDS |
craft\events\RegisterAssetFileKindsEvent | The event that is triggered when registering asset file kinds. | craft\helpers\Assets |
EVENT_SET_FILENAME |
\craft\helpers\SetElementTableAttributeHtmlEvent | The event that is triggered when defining an asset’s filename. | craft\helpers\Assets |
Constant | Value | Description | Defined By |
---|---|---|---|
INDEX_SKIP_ITEMS_PATTERN |
'/.*(Thumbs\.db|__MACOSX|__MACOSX\/|__MACOSX\/.*|\.DS_STORE)$/i' | craft\helpers\Assets |
Method Details
fileTransferList()
public static method
#
Create an Asset transfer list based on a list of Assets and an array of changing folder ids.
public static array fileTransferList ( array $assets, array $folderIdChanges )
$assets |
array | List of assets |
$folderIdChanges |
array | A map of folder id changes |
filename2Title()
public static method
#
Generates a default asset title based on its filename.
public static string filename2Title ( \craft\helpers\string $filename )
$filename |
string | The asset's filename |
generateUrl()
public static method
#
Generate a URL for a given Assets file in a Source Type.
public static string generateUrl ( craft\base\VolumeInterface $volume, craft\elements\Asset $file )
$volume |
craft\base\VolumeInterface | |
$file |
craft\elements\Asset |
getFileKindByExtension()
public static method
#
Return a file's kind by a file's extension.
public static string getFileKindByExtension ( \craft\helpers\string $file )
$file |
string | The file name/path |
return | string | The file kind, or "unknown" if unknown. |
---|
getFileKindLabel()
public static method
#
Returns the label of a given file kind.
public static string getFileKindLabel ( \craft\helpers\string $kind )
$kind |
string |
getFileKinds()
public static method
#
Returns a list of the supported file kinds.
public static array getFileKinds ( )
return | array | The supported file kinds |
---|
getImageEditorSource()
public static method
#
Return an image path to use in Image Editor for an Asset by id and size.
public static false, string getImageEditorSource ( \craft\helpers\int $assetId, \craft\helpers\int $size )
$assetId |
integer | |
$size |
integer | |
throws | yii\base\Exception | in case of failure |
---|
mirrorFolderStructure()
public static method
#
Mirror a folder structure on a Volume.
public static array mirrorFolderStructure ( craft\models\VolumeFolder $sourceParentFolder, craft\models\VolumeFolder $destinationFolder, array $targetTreeMap = [] )
$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 |
return | array | Map of original folder id => new folder id |
---|
parseFileLocation()
public static method
#
Parses a file location in the format of {folder:X}filename.ext
returns the folder ID + filename.
public static array parseFileLocation ( $location )
$location |
string | |
throws | yii\base\Exception | if the file location is invalid |
---|
periodList()
public static method
#
Get a list of available periods for Cache duration settings.
public static array periodList ( )
prepareAssetName()
public static method
#
Clean an Asset's filename.
public static string prepareAssetName ( \craft\helpers\string $name, \craft\helpers\bool $isFilename = true, \craft\helpers\bool $preventPluginModifications = false )
$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 |
sortFolderTree()
public static method
#
Sorts a folder tree by Volume sort order.
public static void sortFolderTree ( array &$tree )
$tree |
tempFilePath()
public static method
#
Get a temporary file path.
public static string tempFilePath ( \craft\helpers\string $extension = 'tmp' )
$extension |
string | Extension to use. "tmp" by default. |
return | string | The temporary file path |
---|---|---|
throws | yii\base\Exception | in case of failure |
urlAppendix()
public static method
#
Get appendix for an URL based on it's Source caching settings.
public static string urlAppendix ( craft\base\VolumeInterface $volume, craft\elements\Asset $file )
$volume |
craft\base\VolumeInterface | |
$file |
craft\elements\Asset |
Event Details
EVENT_REGISTER_FILE_KINDS
event of type craft\events\RegisterAssetFileKindsEvent
#
The event that is triggered when registering asset file kinds.
EVENT_SET_FILENAME
event of type \craft\helpers\SetElementTableAttributeHtmlEvent
#
The event that is triggered when defining an asset’s filename.