| @@ 155-175 (lines=21) @@ | ||
| 152 | * @param string $name The internal field name, passed to forms. |
|
| 153 | * @param string $title The field label. |
|
| 154 | */ |
|
| 155 | public function __construct($name, $title = null) { |
|
| 156 | $this->addExtraClass('ss-upload'); // class, used by js |
|
| 157 | $this->addExtraClass('ss-uploadfield'); // class, used by css for uploadfield only |
|
| 158 | ||
| 159 | $this->ufConfig = array_merge($this->ufConfig, self::config()->defaultConfig); |
|
| 160 | ||
| 161 | parent::__construct($name, $title); |
|
| 162 | ||
| 163 | // AssetField always uses rename replacement method |
|
| 164 | $this->getUpload()->setReplaceFile(false); |
|
| 165 | ||
| 166 | // filter out '' since this would be a regex problem on JS end |
|
| 167 | $this->getValidator()->setAllowedExtensions( |
|
| 168 | array_filter(Config::inst()->get('File', 'allowed_extensions')) |
|
| 169 | ); |
|
| 170 | ||
| 171 | // get the lower max size |
|
| 172 | $maxUpload = File::ini2bytes(ini_get('upload_max_filesize')); |
|
| 173 | $maxPost = File::ini2bytes(ini_get('post_max_size')); |
|
| 174 | $this->getValidator()->setAllowedMaxFileSize(min($maxUpload, $maxPost)); |
|
| 175 | } |
|
| 176 | ||
| 177 | /** |
|
| 178 | * Set name of template used for Buttons on each file (replace, edit, remove, delete) (without path or extension) |
|
| @@ 226-247 (lines=22) @@ | ||
| 223 | * @param SS_List $items If no items are defined, the field will try to auto-detect an existing relation on |
|
| 224 | * @link $record}, with the same name as the field name. |
|
| 225 | */ |
|
| 226 | public function __construct($name, $title = null, SS_List $items = null) { |
|
| 227 | ||
| 228 | // TODO thats the first thing that came to my head, feel free to change it |
|
| 229 | $this->addExtraClass('ss-upload'); // class, used by js |
|
| 230 | $this->addExtraClass('ss-uploadfield'); // class, used by css for uploadfield only |
|
| 231 | ||
| 232 | $this->ufConfig = self::config()->defaultConfig; |
|
| 233 | ||
| 234 | parent::__construct($name, $title); |
|
| 235 | ||
| 236 | if($items) $this->setItems($items); |
|
| 237 | ||
| 238 | // filter out '' since this would be a regex problem on JS end |
|
| 239 | $this->getValidator()->setAllowedExtensions( |
|
| 240 | array_filter(Config::inst()->get('File', 'allowed_extensions')) |
|
| 241 | ); |
|
| 242 | ||
| 243 | // get the lower max size |
|
| 244 | $maxUpload = File::ini2bytes(ini_get('upload_max_filesize')); |
|
| 245 | $maxPost = File::ini2bytes(ini_get('post_max_size')); |
|
| 246 | $this->getValidator()->setAllowedMaxFileSize(min($maxUpload, $maxPost)); |
|
| 247 | } |
|
| 248 | ||
| 249 | /** |
|
| 250 | * Set name of template used for Buttons on each file (replace, edit, remove, delete) (without path or extension) |
|