Assets

Type
Class
Namespace
craft\fields
Inherits
craft\fields\Assets » craft\fields\BaseRelationField
Since
3.0

Assets represents an Assets field.

View source

Public Properties

PropertyDescription
$allowedKindsarray, null – The file kinds that the field should be restricted to (only used if $restrictFiles is true)
$defaultUploadLocationSourcestring, null – Where files should be uploaded to by default, in format "folder:X", where X is the craft\models\VolumeFolder ID (only used if $useSingleFolder is false)
$defaultUploadLocationSubpathstring, null – The subpath that files should be uploaded to by default (only used if $useSingleFolder is false)
$restrictFilesboolean, null – Whether the available assets should be restricted to $allowedKinds
$singleUploadLocationSourcestring, null – Where files should be restricted to, in format "folder:X", where X is the craft\models\VolumeFolder ID (only used if $useSingleFolder is true)
$singleUploadLocationSubpathstring, null – The subpath that files should be restricted to (only used if $useSingleFolder is true)
$useSingleFolderboolean, null – Whether related assets should be limited to a single folder

$allowedKinds

Type
array, null

The file kinds that the field should be restricted to (only used if $restrictFiles is true)

View source

Signature

public array, null $allowedKinds = null

$defaultUploadLocationSource

Type
string, null

Where files should be uploaded to by default, in format "folder:X", where X is the craft\models\VolumeFolder ID (only used if $useSingleFolder is false)

View source

Signature

public string, null $defaultUploadLocationSource = null

$defaultUploadLocationSubpath

Type
string, null

The subpath that files should be uploaded to by default (only used if $useSingleFolder is false)

View source

Signature

public string, null $defaultUploadLocationSubpath = null

$restrictFiles

Type
boolean, null

Whether the available assets should be restricted to $allowedKinds

View source

Signature

public boolean, null $restrictFiles = null

$singleUploadLocationSource

Type
string, null

Where files should be restricted to, in format "folder:X", where X is the craft\models\VolumeFolder ID (only used if $useSingleFolder is true)

View source

Signature

public string, null $singleUploadLocationSource = null

$singleUploadLocationSubpath

Type
string, null

The subpath that files should be restricted to (only used if $useSingleFolder is true)

View source

Signature

public string, null $singleUploadLocationSubpath = null

$useSingleFolder

Type
boolean, null

Whether related assets should be limited to a single folder

View source

Signature

public boolean, null $useSingleFolder = null

Public Methods

MethodDescription
_volumeIdBySourceKey()Returns a volume ID from an upload source key.
afterElementSave()
defaultSelectionLabel()
displayName()
getElementValidationRules()
getFileKindOptions()Returns the available file kind options for the settings
getInputHtml()
getSourceOptions()
init()
isValueEmpty()
normalizeValue()
resolveDynamicPathToFolderId()Resolve source path for uploading for this field.
validateFileSize()Validates the files to make sure they are one of the allowed file kinds.
validateFileType()Validates the files to make sure they are one of the allowed file kinds.

_volumeIdBySourceKey()

Returns a volume ID from an upload source key.

View source

Arguments

Returns

integer, null

Signature

public integer, null _volumeIdBySourceKey ( \craft\fields\string $sourceKey )

afterElementSave()

View source

Arguments

  • $element
  • $isNew

Signature

public void afterElementSave ( craft\base\ElementInterface $element, \craft\fields\bool $isNew )

defaultSelectionLabel()

Signature

public static void defaultSelectionLabel ( )

displayName()

Signature

public static void displayName ( )

getElementValidationRules()

Signature

public void getElementValidationRules ( )

getFileKindOptions()

Returns the available file kind options for the settings

View source

Returns

array

Signature

public array getFileKindOptions ( )

getInputHtml()

View source

Arguments

  • $value
  • $element

Signature

public void getInputHtml ( $value, craft\base\ElementInterface $element = null )

getSourceOptions()

Signature

public void getSourceOptions ( )

init()

Signature

public void init ( )

isValueEmpty()

View source

Arguments

  • $value
  • $element

Signature

public void isValueEmpty ( $value, craft\base\ElementInterface $element )

normalizeValue()

View source

Arguments

  • $value
  • $element

Signature

public void normalizeValue ( $value, craft\base\ElementInterface $element = null )

resolveDynamicPathToFolderId()

Resolve source path for uploading for this field.

View source

Arguments

Returns

integer

Signature

public integer resolveDynamicPathToFolderId ( craft\base\ElementInterface $element = null )

validateFileSize()

Validates the files to make sure they are one of the allowed file kinds.

View source

Arguments

Signature

public void validateFileSize ( craft\base\ElementInterface $element )

validateFileType()

Validates the files to make sure they are one of the allowed file kinds.

View source

Arguments

Signature

public void validateFileType ( craft\base\ElementInterface $element )

Protected Methods

elementType()

Signature

protected static void elementType ( )

inputSelectionCriteria()

Signature

protected void inputSelectionCriteria ( )

inputSources()

View source

Arguments

  • $element

Signature

protected void inputSources ( craft\base\ElementInterface $element = null )

inputTemplateVariables()

View source

Arguments

  • $value
  • $element

Signature

protected void inputTemplateVariables ( $value = null, craft\base\ElementInterface $element = null )