SilverStripe 3.0 API Docs
  • Package
  • Class
  • Tree
  • Deprecated
Version: master
  • master
  • 3.1
  • 3.0
  • 2.4
  • tagfield

Packages

  • cms
    • assets
    • batchaction
    • batchactions
    • content
    • control
    • controller
    • controllers
    • core
    • export
    • filesystem
    • forms
    • model
    • publishers
    • reports
    • search
    • security
    • tasks
  • forms
    • actions
    • core
    • fields-basic
    • fields-dataless
    • fields-datetime
    • fields-files
    • fields-formattedinput
    • fields-relational
    • fields-structural
    • transformations
    • validators
  • framework
    • admin
    • bulkloading
    • control
    • core
    • cron
    • dev
    • email
    • fields-formattedinput
    • fields-relational
    • filesystem
    • formatters
    • forms
    • gridfield
    • i18n
    • injector
    • integration
    • manifest
    • misc
    • model
    • parsers
    • search
    • security
    • tasks
    • testing
    • validation
    • view
  • None
  • PHP

Classes

  • DateField_View_JQuery
  • DatetimeField
  • FormScaffolder
  • GridField_FormAction
  • NestedForm
  • UploadField
  • UploadField_ItemHandler

Class UploadField

Field for uploading single or multiple files of all types, including images. NOTE: this Field will call write() on the supplied record

Features (some might not be available to old browsers):

  • File Drag&Drop support
  • Progressbar
  • Image thumbnail/file icons even before upload finished
  • Saving into relations
  • Edit file
  • allowedExtensions is by default File::$allowed_extensions
  • maxFileSize the value of min(upload_max_filesize,

post_max_size) from php.ini

<>Usage

Object
Extended by ViewableData implements IteratorAggregate
Extended by RequestHandler
Extended by FormField
Extended by FileField
Extended by UploadField
Package: framework\forms
Author: Zauberfisch
Example: <code> $UploadField = new UploadField('myFiles', 'Please upload some images <span>(max. 5 files)</span>'); $UploadField->getValidator()->setAllowedExtensions(array('jpg', 'jpeg', 'png', 'gif')); $UploadField->setConfig('allowedMaxFileNumber', 5); </code>
Located at sapphire/forms/UploadField.php

Methods summary

public
# __construct( string $name, string $title = null, SS_List $items = null )

Parameters

$name
string
$name The internal field name, passed to forms.
$title
string
$title The field label.
$items
SS_List
$items If no items are defined, the field will try to auto-detect an existing relation on

Link

$record}, with the same name as the field name.

Overrides

FileField::__construct
public
# setTemplateFileButtons( String $template )

Set name of template used for Buttons on each file (replace, edit, remove, delete) (without path or extension)

Set name of template used for Buttons on each file (replace, edit, remove, delete) (without path or extension)

Parameters

$template
String
public String
# getTemplateFileButtons( )

Returns

String
public
# setTemplateFileEdit( String $template )

Set name of template used for the edit (inline & popup) of a file file (without path or extension)

Set name of template used for the edit (inline & popup) of a file file (without path or extension)

Parameters

$template
String
public String
# getTemplateFileEdit( )

Returns

String
public
# setRecord( DataObject $record )

Force a record to be used as "Parent" for uploaded Files (eg a Page with a has_one to File)

Force a record to be used as "Parent" for uploaded Files (eg a Page with a has_one to File)

Parameters

$record
DataObject
$record
public DataObject
# getRecord( )

Get the record to use as "Parent" for uploaded Files (eg a Page with a has_one to File) If none is set, it will use Form->getRecord() or Form->Controller()->data()

Get the record to use as "Parent" for uploaded Files (eg a Page with a has_one to File) If none is set, it will use Form->getRecord() or Form->Controller()->data()

Returns

DataObject
public
# setItems( SS_List $items )

Parameters

$items
SS_List
$items
public SS_List
# getItems( )

Returns

SS_List
protected ViewableData_Customised
# customiseFile( File $file )

Hack to add some Variables and a dynamic template to a File

Hack to add some Variables and a dynamic template to a File

Parameters

$file
File
$file

Returns

ViewableData_Customised
public
# setConfig( string $key, mixed $val )

Parameters

$key
string
$key
$val
mixed
$val
public mixed
# getConfig( string $key )

Parameters

$key
string
$key

Returns

mixed
public
# getAutoUpload( )

Used to get config in the template

Used to get config in the template

protected string
# getThumbnailURLForFile( File $file )

Parameters

$file
File
$file

Returns

string
public array
# getAttributes( )

Returns

array

Overrides

FileField::getAttributes
public string
# extraClass( )

Compiles all CSS-classes. Optionally includes a "nolabel"-class if no title was set on the formfield. Uses FormField::Message() and FormField::MessageType() to add validatoin error classes which can be used to style the contained tags.

Compiles all CSS-classes. Optionally includes a "nolabel"-class if no title was set on the formfield. Uses FormField::Message() and FormField::MessageType() to add validatoin error classes which can be used to style the contained tags.

Returns

string
CSS-classnames

Overrides

FormField::extraClass
public string
# Field( array $properties = array() )

Returns the form field - used by templates. Although FieldHolder is generally what is inserted into templates, all of the field holder templates make use of $Field. It's expected that FieldHolder will give you the "complete" representation of the field on the form, whereas Field will give you the core editing widget, such as an input tag.

Returns the form field - used by templates. Although FieldHolder is generally what is inserted into templates, all of the field holder templates make use of $Field. It's expected that FieldHolder will give you the "complete" representation of the field on the form, whereas Field will give you the core editing widget, such as an input tag.

Parameters

$properties
array
$properties key value pairs of template variables

Returns

string

Overrides

FileField::Field
public Boolean
# validate( mixed $validator )

Validation method for this field, called when the entire form is validated

Validation method for this field, called when the entire form is validated

Parameters

$validator
mixed
$validator

Returns

Boolean

Overrides

FileField::validate
public UploadField_ItemHandler
# handleItem( SS_HTTPRequest $request )

Parameters

$request
SS_HTTPRequest
$request

Returns

UploadField_ItemHandler
public UploadField_ItemHandler
# getItemHandler( integer $itemID )

Parameters

$itemID
integer
$itemID

Returns

UploadField_ItemHandler
public UploadField_ItemHandler
# handleSelect( SS_HTTPRequest $request )

Parameters

$request
SS_HTTPRequest
$request

Returns

UploadField_ItemHandler
public string
# upload( SS_HTTPRequest $request )

Action to handle upload of a single file

Action to handle upload of a single file

Parameters

$request
SS_HTTPRequest
$request

Returns

string
json
public
# attach( mixed $request )

Add existing File records to the relationship.

Add existing File records to the relationship.

protected
# attachFile( File $file )

Parameters

$file
File
public
# performReadonlyTransformation( )

Returns a readonly version of this field

Returns a readonly version of this field

Overrides

FormField::performReadonlyTransformation
public boolean
# managesRelation( )

Determines if the underlying record (if any) has a relationship matching the field name. Important for permission control.

Determines if the underlying record (if any) has a relationship matching the field name. Important for permission control.

Returns

boolean
public string
# getRelationAutosetClass( )

Gets the foreign class that needs to be created.

Gets the foreign class that needs to be created.

Returns

string
Foreign class name.
public boolean
# isDisabled( )

Returns

boolean

Overrides

FormField::isDisabled
public boolean
# isSaveable( )

Determines if the field can be saved into a database record.

Determines if the field can be saved into a database record.

Returns

boolean
public
# canUpload( )
public
# canAttachExisting( )

Methods inherited from FileField

Value(), getFolderName(), getUpload(), getValidator(), saveInto(), setFolderName(), setUpload(), setValidator()

Methods inherited from FormField

FieldHolder(), ID(), LeftTitle(), Link(), Message(), MessageType(), Name(), Required(), RightTitle(), SmallFieldHolder(), Title(), Type(), addExtraClass(), attrTitle(), attrValue(), createTag(), dataValue(), debug(), describe(), forTemplate(), getAttribute(), getAttributesHTML(), getCustomValidationMessage(), getDescription(), getFieldHolderTemplate(), getFieldHolderTemplates(), getForm(), getName(), getSmallFieldHolderTemplate(), getSmallFieldHolderTemplates(), getTabIndex(), getTemplate(), getTemplates(), hasClass(), hasData(), isComposite(), isReadonly(), name_to_label(), performDisabledTransformation(), removeExtraClass(), rootFieldList(), rootFieldSet(), securityTokenEnabled(), setAttribute(), setContainerFieldList(), setContainerFieldSet(), setCustomValidationMessage(), setDescription(), setDisabled(), setError(), setFieldHolderTemplate(), setForm(), setLeftTitle(), setName(), setReadonly(), setRightTitle(), setSmallFieldHolderTemplate(), setTabIndex(), setTemplate(), setTitle(), setValue(), transform()

Methods inherited from RequestHandler

allowedActions(), checkAccessAction(), getRequest(), handleRequest(), hasAction(), httpError(), isAjax(), setDataModel(), setRequest()

Methods inherited from ViewableData

ATT_val(), CSSClasses(), Debug(), JS_val(), Me(), RAW_val(), SQL_val(), ThemeDir(), XML_val(), __get(), __isset(), __set(), buildCastingCache(), cachedCall(), castingClass(), castingHelper(), castingHelperPair(), castingObjectCreator(), castingObjectCreatorPair(), customise(), defineMethods(), escapeTypeForField(), getField(), getIterator(), getXMLValues(), hasField(), hasValue(), obj(), renderWith(), setCustomisedObj(), setField()

Methods inherited from Object

__call(), __toString(), addMethodsFrom(), addStaticVars(), addWrapperMethod(), add_extension(), add_static_var(), allMethodNames(), cacheToFile(), clearCache(), combined_static(), config(), create(), createMethod(), create_from_string(), exists(), extend(), getCustomClass(), getExtensionInstance(), getExtensionInstances(), get_extensions(), get_extra_config_sources(), get_static(), hasExtension(), hasMethod(), has_extension(), invokeWithExtensions(), is_a(), loadCache(), parentClass(), parse_class_spec(), remove_extension(), sanitiseCachename(), saveCache(), set_stat(), set_static(), set_uninherited(), stat(), static_lookup(), strong_create(), uninherited(), uninherited_static(), useCustomClass()

Magic methods summary

Properties summary

public static array $allowed_actions
#
public static array $url_handlers
#
protected String $templateFileButtons
#
protected String $templateFileEdit
#
protected DataObject $record
#
protected SS_List $items
#
protected array $ufConfig
#

Config for this field used in both, php and javascript (will be merged into the config of the javascript file upload plugin). See framework/_config/uploadfield.yml for configuration defaults and documentation.

Config for this field used in both, php and javascript (will be merged into the config of the javascript file upload plugin). See framework/_config/uploadfield.yml for configuration defaults and documentation.

Properties inherited from FileField

$allowedExtensions, $allowedMaxFileSize, $folderName, $relationAutoSetting, $upload

Properties inherited from FormField

$attributes, $containerFieldList, $customValidationMessage, $description, $disabled, $dontEscape, $extraClass, $extraClasses, $fieldHolderTemplate, $form, $leftTitle, $message, $messageType, $name, $readonly, $rightTitle, $smallFieldHolderTemplate, $template, $title, $value

Properties inherited from RequestHandler

$brokenOnConstruct, $model, $request

Properties inherited from ViewableData

$casting, $customisedObject, $default_cast, $failover

Properties inherited from Object

$class, $extension_instances, $extensions

Comments

Comment policy: Please use comments for tips and corrections about the described functionality. Comments are moderated, we reserve the right to remove comments that are inappropriate or are no longer relevant.
Use the Silverstripe Forum to ask questions.
blog comments powered by Disqus
SilverStripe 3.0 API Docs API documentation generated by ApiGen 2.8.0