Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like UploadField often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use UploadField, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 41 | class UploadField extends FileField { |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @var array |
||
| 45 | */ |
||
| 46 | private static $allowed_actions = array( |
||
|
|
|||
| 47 | 'upload', |
||
| 48 | 'attach', |
||
| 49 | 'handleItem', |
||
| 50 | 'handleSelect', |
||
| 51 | 'fileexists' |
||
| 52 | ); |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @var array |
||
| 56 | */ |
||
| 57 | private static $url_handlers = array( |
||
| 58 | 'item/$ID' => 'handleItem', |
||
| 59 | 'select' => 'handleSelect', |
||
| 60 | '$Action!' => '$Action', |
||
| 61 | ); |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Template to use for the file button widget |
||
| 65 | * |
||
| 66 | * @var string |
||
| 67 | */ |
||
| 68 | protected $templateFileButtons = 'Includes/UploadField_FileButtons'; |
||
| 69 | |||
| 70 | /** |
||
| 71 | * Template to use for the edit form |
||
| 72 | * |
||
| 73 | * @var string |
||
| 74 | */ |
||
| 75 | protected $templateFileEdit = 'UploadField_FileEdit'; |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Parent data record. Will be infered from parent form or controller if blank. |
||
| 79 | * |
||
| 80 | * @var DataObject |
||
| 81 | */ |
||
| 82 | protected $record; |
||
| 83 | |||
| 84 | /** |
||
| 85 | * Items loaded into this field. May be a RelationList, or any other SS_List |
||
| 86 | * |
||
| 87 | * @var SS_List |
||
| 88 | */ |
||
| 89 | protected $items; |
||
| 90 | |||
| 91 | /** |
||
| 92 | * Config for this field used in the front-end javascript |
||
| 93 | * (will be merged into the config of the javascript file upload plugin). |
||
| 94 | * |
||
| 95 | * @var array |
||
| 96 | */ |
||
| 97 | protected $ufConfig = array(); |
||
| 98 | |||
| 99 | /** |
||
| 100 | * Front end config defaults |
||
| 101 | * |
||
| 102 | * @config |
||
| 103 | * @var array |
||
| 104 | */ |
||
| 105 | private static $defaultConfig = array( |
||
| 106 | /** |
||
| 107 | * Automatically upload the file once selected |
||
| 108 | * |
||
| 109 | * @var boolean |
||
| 110 | */ |
||
| 111 | 'autoUpload' => true, |
||
| 112 | /** |
||
| 113 | * Restriction on number of files that may be set for this field. Set to null to allow |
||
| 114 | * unlimited. If record has a has_one and allowedMaxFileNumber is null, it will be set to 1. |
||
| 115 | * The resulting value will be set to maxNumberOfFiles |
||
| 116 | * |
||
| 117 | * @var integer |
||
| 118 | */ |
||
| 119 | 'allowedMaxFileNumber' => null, |
||
| 120 | /** |
||
| 121 | * Can the user upload new files, or just select from existing files. |
||
| 122 | * String values are interpreted as permission codes. |
||
| 123 | * |
||
| 124 | * @var boolean|string |
||
| 125 | */ |
||
| 126 | 'canUpload' => true, |
||
| 127 | /** |
||
| 128 | * Can the user attach files from the assets archive on the site? |
||
| 129 | * String values are interpreted as permission codes. |
||
| 130 | * |
||
| 131 | * @var boolean|string |
||
| 132 | */ |
||
| 133 | 'canAttachExisting' => "CMS_ACCESS_AssetAdmin", |
||
| 134 | /** |
||
| 135 | * Shows the target folder for new uploads in the field UI. |
||
| 136 | * Disable to keep the internal filesystem structure hidden from users. |
||
| 137 | * |
||
| 138 | * @var boolean|string |
||
| 139 | */ |
||
| 140 | 'canPreviewFolder' => true, |
||
| 141 | /** |
||
| 142 | * Indicate a change event to the containing form if an upload |
||
| 143 | * or file edit/delete was performed. |
||
| 144 | * |
||
| 145 | * @var boolean |
||
| 146 | */ |
||
| 147 | 'changeDetection' => true, |
||
| 148 | /** |
||
| 149 | * Maximum width of the preview thumbnail |
||
| 150 | * |
||
| 151 | * @var integer |
||
| 152 | */ |
||
| 153 | 'previewMaxWidth' => 80, |
||
| 154 | /** |
||
| 155 | * Maximum height of the preview thumbnail |
||
| 156 | * |
||
| 157 | * @var integer |
||
| 158 | */ |
||
| 159 | 'previewMaxHeight' => 60, |
||
| 160 | /** |
||
| 161 | * javascript template used to display uploading files |
||
| 162 | * |
||
| 163 | * @see javascript/UploadField_uploadtemplate.js |
||
| 164 | * @var string |
||
| 165 | */ |
||
| 166 | 'uploadTemplateName' => 'ss-uploadfield-uploadtemplate', |
||
| 167 | /** |
||
| 168 | * javascript template used to display already uploaded files |
||
| 169 | * |
||
| 170 | * @see javascript/UploadField_downloadtemplate.js |
||
| 171 | * @var string |
||
| 172 | */ |
||
| 173 | 'downloadTemplateName' => 'ss-uploadfield-downloadtemplate', |
||
| 174 | /** |
||
| 175 | * Show a warning when overwriting a file. |
||
| 176 | * This requires Upload->replaceFile config to be set to true, otherwise |
||
| 177 | * files will be renamed instead of overwritten |
||
| 178 | * |
||
| 179 | * @see Upload |
||
| 180 | * @var boolean |
||
| 181 | */ |
||
| 182 | 'overwriteWarning' => true |
||
| 183 | ); |
||
| 184 | |||
| 185 | /** |
||
| 186 | * @var String Folder to display in "Select files" list. |
||
| 187 | * Defaults to listing all files regardless of folder. |
||
| 188 | * The folder path should be relative to the webroot. |
||
| 189 | * See {@link FileField->folderName} to set the upload target instead. |
||
| 190 | * @example admin/folder/subfolder |
||
| 191 | */ |
||
| 192 | protected $displayFolderName; |
||
| 193 | |||
| 194 | /** |
||
| 195 | * FieldList $fields or string $name (of a method on File to provide a fields) for the EditForm |
||
| 196 | * @example 'getCMSFields' |
||
| 197 | * |
||
| 198 | * @var FieldList|string |
||
| 199 | */ |
||
| 200 | protected $fileEditFields = null; |
||
| 201 | |||
| 202 | /** |
||
| 203 | * FieldList $actions or string $name (of a method on File to provide a actions) for the EditForm |
||
| 204 | * @example 'getCMSActions' |
||
| 205 | * |
||
| 206 | * @var FieldList|string |
||
| 207 | */ |
||
| 208 | protected $fileEditActions = null; |
||
| 209 | |||
| 210 | /** |
||
| 211 | * Validator (eg RequiredFields) or string $name (of a method on File to provide a Validator) for the EditForm |
||
| 212 | * @example 'getCMSValidator' |
||
| 213 | * |
||
| 214 | * @var RequiredFields|string |
||
| 215 | */ |
||
| 216 | protected $fileEditValidator = null; |
||
| 217 | |||
| 218 | /** |
||
| 219 | * Construct a new UploadField instance |
||
| 220 | * |
||
| 221 | * @param string $name The internal field name, passed to forms. |
||
| 222 | * @param string $title The field label. |
||
| 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 | View Code Duplication | public function __construct($name, $title = null, SS_List $items = null) { |
|
| 248 | |||
| 249 | /** |
||
| 250 | * Set name of template used for Buttons on each file (replace, edit, remove, delete) (without path or extension) |
||
| 251 | * |
||
| 252 | * @param string $template |
||
| 253 | * @return $this |
||
| 254 | */ |
||
| 255 | public function setTemplateFileButtons($template) { |
||
| 259 | |||
| 260 | /** |
||
| 261 | * @return string |
||
| 262 | */ |
||
| 263 | public function getTemplateFileButtons() { |
||
| 266 | |||
| 267 | /** |
||
| 268 | * Set name of template used for the edit (inline & popup) of a file file (without path or extension) |
||
| 269 | * |
||
| 270 | * @param string $template |
||
| 271 | * @return $this |
||
| 272 | */ |
||
| 273 | public function setTemplateFileEdit($template) { |
||
| 277 | |||
| 278 | /** |
||
| 279 | * @return string |
||
| 280 | */ |
||
| 281 | public function getTemplateFileEdit() { |
||
| 284 | |||
| 285 | /** |
||
| 286 | * Determine if the target folder for new uploads in is visible the field UI. |
||
| 287 | * |
||
| 288 | * @return boolean |
||
| 289 | */ |
||
| 290 | public function canPreviewFolder() { |
||
| 295 | |||
| 296 | /** |
||
| 297 | * Determine if the target folder for new uploads in is visible the field UI. |
||
| 298 | * Disable to keep the internal filesystem structure hidden from users. |
||
| 299 | * |
||
| 300 | * @param boolean|string $canPreviewFolder Either a boolean flag, or a |
||
| 301 | * required permission code |
||
| 302 | * @return UploadField Self reference |
||
| 303 | */ |
||
| 304 | public function setCanPreviewFolder($canPreviewFolder) { |
||
| 307 | |||
| 308 | /** |
||
| 309 | * Determine if the field should show a warning when overwriting a file. |
||
| 310 | * This requires Upload->replaceFile config to be set to true, otherwise |
||
| 311 | * files will be renamed instead of overwritten (although the warning will |
||
| 312 | * still be displayed) |
||
| 313 | * |
||
| 314 | * @return boolean |
||
| 315 | */ |
||
| 316 | public function getOverwriteWarning() { |
||
| 319 | |||
| 320 | /** |
||
| 321 | * Determine if the field should show a warning when overwriting a file. |
||
| 322 | * This requires Upload->replaceFile config to be set to true, otherwise |
||
| 323 | * files will be renamed instead of overwritten (although the warning will |
||
| 324 | * still be displayed) |
||
| 325 | * |
||
| 326 | * @param boolean $overwriteWarning |
||
| 327 | * @return UploadField Self reference |
||
| 328 | */ |
||
| 329 | public function setOverwriteWarning($overwriteWarning) { |
||
| 332 | |||
| 333 | /** |
||
| 334 | * @param string $name |
||
| 335 | * @return $this |
||
| 336 | */ |
||
| 337 | public function setDisplayFolderName($name) { |
||
| 341 | |||
| 342 | /** |
||
| 343 | * @return String |
||
| 344 | */ |
||
| 345 | public function getDisplayFolderName() { |
||
| 348 | |||
| 349 | /** |
||
| 350 | * Force a record to be used as "Parent" for uploaded Files (eg a Page with a has_one to File) |
||
| 351 | * |
||
| 352 | * @param DataObject $record |
||
| 353 | * @return $this |
||
| 354 | */ |
||
| 355 | public function setRecord($record) { |
||
| 359 | /** |
||
| 360 | * 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 |
||
| 361 | * use Form->getRecord() or Form->Controller()->data() |
||
| 362 | * |
||
| 363 | * @return DataObject |
||
| 364 | */ |
||
| 365 | public function getRecord() { |
||
| 379 | |||
| 380 | /** |
||
| 381 | * Loads the related record values into this field. UploadField can be uploaded |
||
| 382 | * in one of three ways: |
||
| 383 | * |
||
| 384 | * - By passing in a list of file IDs in the $value parameter (an array with a single |
||
| 385 | * key 'Files', with the value being the actual array of IDs). |
||
| 386 | * - By passing in an explicit list of File objects in the $record parameter, and |
||
| 387 | * leaving $value blank. |
||
| 388 | * - By passing in a dataobject in the $record parameter, from which file objects |
||
| 389 | * will be extracting using the field name as the relation field. |
||
| 390 | * |
||
| 391 | * Each of these methods will update both the items (list of File objects) and the |
||
| 392 | * field value (list of file ID values). |
||
| 393 | * |
||
| 394 | * @param array $value Array of submitted form data, if submitting from a form |
||
| 395 | * @param array|DataObject|SS_List $record Full source record, either as a DataObject, |
||
| 396 | * SS_List of items, or an array of submitted form data |
||
| 397 | * @return $this Self reference |
||
| 398 | * @throws ValidationException |
||
| 399 | */ |
||
| 400 | public function setValue($value, $record = null) { |
||
| 466 | |||
| 467 | /** |
||
| 468 | * Sets the items assigned to this field as an SS_List of File objects. |
||
| 469 | * Calling setItems will also update the value of this field, as well as |
||
| 470 | * updating the internal list of File items. |
||
| 471 | * |
||
| 472 | * @param SS_List $items |
||
| 473 | * @return UploadField self reference |
||
| 474 | */ |
||
| 475 | public function setItems(SS_List $items) { |
||
| 478 | |||
| 479 | /** |
||
| 480 | * Retrieves the current list of files |
||
| 481 | * |
||
| 482 | * @return SS_List |
||
| 483 | */ |
||
| 484 | public function getItems() { |
||
| 487 | |||
| 488 | /** |
||
| 489 | * Retrieves a customised list of all File records to ensure they are |
||
| 490 | * properly viewable when rendered in the field template. |
||
| 491 | * |
||
| 492 | * @return SS_List[ViewableData_Customised] |
||
| 493 | */ |
||
| 494 | public function getCustomisedItems() { |
||
| 501 | |||
| 502 | /** |
||
| 503 | * Retrieves the list of selected file IDs |
||
| 504 | * |
||
| 505 | * @return array |
||
| 506 | */ |
||
| 507 | public function getItemIDs() { |
||
| 511 | |||
| 512 | public function Value() { |
||
| 516 | |||
| 517 | public function saveInto(DataObjectInterface $record) { |
||
| 536 | |||
| 537 | /** |
||
| 538 | * Customises a file with additional details suitable for rendering in the |
||
| 539 | * UploadField.ss template |
||
| 540 | * |
||
| 541 | * @param AssetContainer $file |
||
| 542 | * @return ViewableData_Customised |
||
| 543 | */ |
||
| 544 | protected function customiseFile(AssetContainer $file) { |
||
| 556 | |||
| 557 | /** |
||
| 558 | * Assign a front-end config variable for the upload field |
||
| 559 | * |
||
| 560 | * @see https://github.com/blueimp/jQuery-File-Upload/wiki/Options for the list of front end options available |
||
| 561 | * |
||
| 562 | * @param string $key |
||
| 563 | * @param mixed $val |
||
| 564 | * @return UploadField self reference |
||
| 565 | */ |
||
| 566 | public function setConfig($key, $val) { |
||
| 570 | |||
| 571 | /** |
||
| 572 | * Gets a front-end config variable for the upload field |
||
| 573 | * |
||
| 574 | * @see https://github.com/blueimp/jQuery-File-Upload/wiki/Options for the list of front end options available |
||
| 575 | * |
||
| 576 | * @param string $key |
||
| 577 | * @return mixed |
||
| 578 | */ |
||
| 579 | public function getConfig($key) { |
||
| 583 | |||
| 584 | /** |
||
| 585 | * Determine if the field should automatically upload the file. |
||
| 586 | * |
||
| 587 | * @return boolean |
||
| 588 | */ |
||
| 589 | public function getAutoUpload() { |
||
| 592 | |||
| 593 | /** |
||
| 594 | * Determine if the field should automatically upload the file |
||
| 595 | * |
||
| 596 | * @param boolean $autoUpload |
||
| 597 | * @return UploadField Self reference |
||
| 598 | */ |
||
| 599 | public function setAutoUpload($autoUpload) { |
||
| 602 | |||
| 603 | /** |
||
| 604 | * Determine maximum number of files allowed to be attached |
||
| 605 | * Defaults to 1 for has_one and null (unlimited) for |
||
| 606 | * many_many and has_many relations. |
||
| 607 | * |
||
| 608 | * @return integer|null Maximum limit, or null for no limit |
||
| 609 | */ |
||
| 610 | public function getAllowedMaxFileNumber() { |
||
| 627 | |||
| 628 | /** |
||
| 629 | * Determine maximum number of files allowed to be attached. |
||
| 630 | * |
||
| 631 | * @param integer|null $allowedMaxFileNumber Maximum limit. 0 or null will be treated as unlimited |
||
| 632 | * @return UploadField Self reference |
||
| 633 | */ |
||
| 634 | public function setAllowedMaxFileNumber($allowedMaxFileNumber) { |
||
| 637 | |||
| 638 | /** |
||
| 639 | * Determine if the user has permission to upload. |
||
| 640 | * |
||
| 641 | * @return boolean |
||
| 642 | */ |
||
| 643 | public function canUpload() { |
||
| 648 | |||
| 649 | /** |
||
| 650 | * Specify whether the user can upload files. |
||
| 651 | * String values will be treated as required permission codes |
||
| 652 | * |
||
| 653 | * @param boolean|string $canUpload Either a boolean flag, or a required |
||
| 654 | * permission code |
||
| 655 | * @return UploadField Self reference |
||
| 656 | */ |
||
| 657 | public function setCanUpload($canUpload) { |
||
| 660 | |||
| 661 | /** |
||
| 662 | * Determine if the user has permission to attach existing files |
||
| 663 | * By default returns true if the user has the CMS_ACCESS_AssetAdmin permission |
||
| 664 | * |
||
| 665 | * @return boolean |
||
| 666 | */ |
||
| 667 | public function canAttachExisting() { |
||
| 672 | |||
| 673 | /** |
||
| 674 | * Returns true if the field is neither readonly nor disabled |
||
| 675 | * |
||
| 676 | * @return boolean |
||
| 677 | */ |
||
| 678 | public function isActive() { |
||
| 681 | |||
| 682 | /** |
||
| 683 | * Specify whether the user can attach existing files |
||
| 684 | * String values will be treated as required permission codes |
||
| 685 | * |
||
| 686 | * @param boolean|string $canAttachExisting Either a boolean flag, or a |
||
| 687 | * required permission code |
||
| 688 | * @return UploadField Self reference |
||
| 689 | */ |
||
| 690 | public function setCanAttachExisting($canAttachExisting) { |
||
| 693 | |||
| 694 | /** |
||
| 695 | * Gets thumbnail width. Defaults to 80 |
||
| 696 | * |
||
| 697 | * @return integer |
||
| 698 | */ |
||
| 699 | public function getPreviewMaxWidth() { |
||
| 702 | |||
| 703 | /** |
||
| 704 | * @see UploadField::getPreviewMaxWidth() |
||
| 705 | * |
||
| 706 | * @param integer $previewMaxWidth |
||
| 707 | * @return UploadField Self reference |
||
| 708 | */ |
||
| 709 | public function setPreviewMaxWidth($previewMaxWidth) { |
||
| 712 | |||
| 713 | /** |
||
| 714 | * Gets thumbnail height. Defaults to 60 |
||
| 715 | * |
||
| 716 | * @return integer |
||
| 717 | */ |
||
| 718 | public function getPreviewMaxHeight() { |
||
| 721 | |||
| 722 | /** |
||
| 723 | * @see UploadField::getPreviewMaxHeight() |
||
| 724 | * |
||
| 725 | * @param integer $previewMaxHeight |
||
| 726 | * @return UploadField Self reference |
||
| 727 | */ |
||
| 728 | public function setPreviewMaxHeight($previewMaxHeight) { |
||
| 731 | |||
| 732 | /** |
||
| 733 | * javascript template used to display uploading files |
||
| 734 | * Defaults to 'ss-uploadfield-uploadtemplate' |
||
| 735 | * |
||
| 736 | * @see javascript/UploadField_uploadtemplate.js |
||
| 737 | * @return string |
||
| 738 | */ |
||
| 739 | public function getUploadTemplateName() { |
||
| 742 | |||
| 743 | /** |
||
| 744 | * @see UploadField::getUploadTemplateName() |
||
| 745 | * |
||
| 746 | * @param string $uploadTemplateName |
||
| 747 | * @return UploadField Self reference |
||
| 748 | */ |
||
| 749 | public function setUploadTemplateName($uploadTemplateName) { |
||
| 752 | |||
| 753 | /** |
||
| 754 | * javascript template used to display already uploaded files |
||
| 755 | * Defaults to 'ss-downloadfield-downloadtemplate' |
||
| 756 | * |
||
| 757 | * @see javascript/DownloadField_downloadtemplate.js |
||
| 758 | * @return string |
||
| 759 | */ |
||
| 760 | public function getDownloadTemplateName() { |
||
| 763 | |||
| 764 | /** |
||
| 765 | * @see Uploadfield::getDownloadTemplateName() |
||
| 766 | * |
||
| 767 | * @param string $downloadTemplateName |
||
| 768 | * @return Uploadfield Self reference |
||
| 769 | */ |
||
| 770 | public function setDownloadTemplateName($downloadTemplateName) { |
||
| 773 | |||
| 774 | /** |
||
| 775 | * FieldList $fields for the EditForm |
||
| 776 | * @example 'getCMSFields' |
||
| 777 | * |
||
| 778 | * @param DataObject $file File context to generate fields for |
||
| 779 | * @return FieldList List of form fields |
||
| 780 | */ |
||
| 781 | public function getFileEditFields(DataObject $file) { |
||
| 804 | |||
| 805 | /** |
||
| 806 | * FieldList $fields or string $name (of a method on File to provide a fields) for the EditForm |
||
| 807 | * @example 'getCMSFields' |
||
| 808 | * |
||
| 809 | * @param FieldList|string |
||
| 810 | * @return Uploadfield Self reference |
||
| 811 | */ |
||
| 812 | public function setFileEditFields($fileEditFields) { |
||
| 816 | |||
| 817 | /** |
||
| 818 | * FieldList $actions or string $name (of a method on File to provide a actions) for the EditForm |
||
| 819 | * @example 'getCMSActions' |
||
| 820 | * |
||
| 821 | * @param DataObject $file File context to generate form actions for |
||
| 822 | * @return FieldList Field list containing FormAction |
||
| 823 | */ |
||
| 824 | public function getFileEditActions(DataObject $file) { |
||
| 844 | |||
| 845 | /** |
||
| 846 | * FieldList $actions or string $name (of a method on File to provide a actions) for the EditForm |
||
| 847 | * @example 'getCMSActions' |
||
| 848 | * |
||
| 849 | * @param FieldList|string |
||
| 850 | * @return Uploadfield Self reference |
||
| 851 | */ |
||
| 852 | public function setFileEditActions($fileEditActions) { |
||
| 856 | |||
| 857 | /** |
||
| 858 | * Determines the validator to use for the edit form |
||
| 859 | * @example 'getCMSValidator' |
||
| 860 | * |
||
| 861 | * @param DataObject $file File context to generate validator from |
||
| 862 | * @return Validator Validator object |
||
| 863 | */ |
||
| 864 | public function getFileEditValidator(DataObject $file) { |
||
| 882 | |||
| 883 | /** |
||
| 884 | * Validator (eg RequiredFields) or string $name (of a method on File to provide a Validator) for the EditForm |
||
| 885 | * @example 'getCMSValidator' |
||
| 886 | * |
||
| 887 | * @param Validator|string |
||
| 888 | * @return Uploadfield Self reference |
||
| 889 | */ |
||
| 890 | public function setFileEditValidator($fileEditValidator) { |
||
| 894 | |||
| 895 | /** |
||
| 896 | * |
||
| 897 | * @param AssetContainer $file |
||
| 898 | * @return string URL to thumbnail |
||
| 899 | */ |
||
| 900 | protected function getThumbnailURLForFile(AssetContainer $file) { |
||
| 923 | |||
| 924 | public function getAttributes() { |
||
| 930 | |||
| 931 | public function extraClass() { |
||
| 941 | |||
| 942 | public function Field($properties = array()) { |
||
| 1004 | |||
| 1005 | /** |
||
| 1006 | * Validation method for this field, called when the entire form is validated |
||
| 1007 | * |
||
| 1008 | * @param Validator $validator |
||
| 1009 | * @return boolean |
||
| 1010 | */ |
||
| 1011 | public function validate($validator) { |
||
| 1057 | |||
| 1058 | /** |
||
| 1059 | * @param SS_HTTPRequest $request |
||
| 1060 | * @return UploadField_ItemHandler |
||
| 1061 | */ |
||
| 1062 | public function handleItem(SS_HTTPRequest $request) { |
||
| 1065 | |||
| 1066 | /** |
||
| 1067 | * @param int $itemID |
||
| 1068 | * @return UploadField_ItemHandler |
||
| 1069 | */ |
||
| 1070 | public function getItemHandler($itemID) { |
||
| 1073 | |||
| 1074 | /** |
||
| 1075 | * @param SS_HTTPRequest $request |
||
| 1076 | * @return UploadField_ItemHandler |
||
| 1077 | */ |
||
| 1078 | public function handleSelect(SS_HTTPRequest $request) { |
||
| 1082 | |||
| 1083 | /** |
||
| 1084 | * Given an array of post variables, extract all temporary file data into an array |
||
| 1085 | * |
||
| 1086 | * @param array $postVars Array of posted form data |
||
| 1087 | * @return array List of temporary file data |
||
| 1088 | */ |
||
| 1089 | protected function extractUploadedFileData($postVars) { |
||
| 1114 | |||
| 1115 | /** |
||
| 1116 | * Loads the temporary file data into a File object |
||
| 1117 | * |
||
| 1118 | * @param array $tmpFile Temporary file data |
||
| 1119 | * @param string $error Error message |
||
| 1120 | * @return AssetContainer File object, or null if error |
||
| 1121 | */ |
||
| 1122 | protected function saveTemporaryFile($tmpFile, &$error = null) { |
||
| 1171 | |||
| 1172 | /** |
||
| 1173 | * Safely encodes the File object with all standard fields required |
||
| 1174 | * by the front end |
||
| 1175 | * |
||
| 1176 | * @param AssetContainer $file Object which contains a file |
||
| 1177 | * @return array Array encoded list of file attributes |
||
| 1178 | */ |
||
| 1179 | protected function encodeFileAttributes(AssetContainer $file) { |
||
| 1194 | |||
| 1195 | /** |
||
| 1196 | * Action to handle upload of a single file |
||
| 1197 | * |
||
| 1198 | * @param SS_HTTPRequest $request |
||
| 1199 | * @return SS_HTTPResponse |
||
| 1200 | * @return SS_HTTPResponse |
||
| 1201 | */ |
||
| 1202 | public function upload(SS_HTTPRequest $request) { |
||
| 1236 | |||
| 1237 | /** |
||
| 1238 | * Retrieves details for files that this field wishes to attache to the |
||
| 1239 | * client-side form |
||
| 1240 | * |
||
| 1241 | * @param SS_HTTPRequest $request |
||
| 1242 | * @return SS_HTTPResponse |
||
| 1243 | */ |
||
| 1244 | public function attach(SS_HTTPRequest $request) { |
||
| 1258 | |||
| 1259 | /** |
||
| 1260 | * Check if file exists, both checking filtered filename and exact filename |
||
| 1261 | * |
||
| 1262 | * @param string $originalFile Filename |
||
| 1263 | * @return bool |
||
| 1264 | */ |
||
| 1265 | protected function checkFileExists($originalFile) { |
||
| 1279 | |||
| 1280 | /** |
||
| 1281 | * Determines if a specified file exists |
||
| 1282 | * |
||
| 1283 | * @param SS_HTTPRequest $request |
||
| 1284 | * @return SS_HTTPResponse |
||
| 1285 | */ |
||
| 1286 | public function fileexists(SS_HTTPRequest $request) { |
||
| 1305 | |||
| 1306 | public function performReadonlyTransformation() { |
||
| 1312 | |||
| 1313 | /** |
||
| 1314 | * Gets the foreign class that needs to be created, or 'File' as default if there |
||
| 1315 | * is no relationship, or it cannot be determined. |
||
| 1316 | * |
||
| 1317 | * @param string $default Default value to return if no value could be calculated |
||
| 1318 | * @return string Foreign class name. |
||
| 1319 | */ |
||
| 1320 | View Code Duplication | public function getRelationAutosetClass($default = 'File') { |
|
| 1335 | |||
| 1336 | } |
||
| 1337 | |||
| 1648 |