mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
e0614530c6
http://svn.silverstripe.com/open/modules/sapphire/branches/2.2.1asfonz ........ r48451 | jshipman | 2008-01-23 14:42:20 +1300 (Wed, 23 Jan 2008) | 1 line ........ git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@48541 467b73ca-7a2a-4603-9d3b-597d59a354a9
52 lines
1.4 KiB
PHP
Executable File
52 lines
1.4 KiB
PHP
Executable File
<?php
|
|
|
|
/**
|
|
* @package forms
|
|
* @subpackage fields-files
|
|
*/
|
|
|
|
/**
|
|
* A field that will upload files to a page for use within the CMS.
|
|
* @package forms
|
|
* @subpackage fields-files
|
|
*/
|
|
class FileIFrameField extends FileField {
|
|
|
|
public function Field() {
|
|
$data = $this->form->getRecord();
|
|
|
|
if($data->ID && is_numeric($data->ID)) {
|
|
$idxField = $this->name . 'ID';
|
|
$hiddenField = "<input type=\"hidden\" id=\"" . $this->id() . "\" name=\"$idxField\" value=\"" . $this->attrValue() . "\" />";
|
|
|
|
$parentClass = $data->class;
|
|
|
|
$parentID = $data->ID;
|
|
$parentField = $this->name;
|
|
$iframe = "<iframe name=\"{$this->name}_iframe\" src=\"images/iframe/$parentClass/$parentID/$parentField\" style=\"height: 152px; width: 600px; border-style: none;\"></iframe>";
|
|
|
|
return $iframe . $hiddenField;
|
|
|
|
} else {
|
|
$this->value = _t('FileIframeField.NOTEADDFILES', 'You can add files once you have saved for the first time.');
|
|
return FormField::Field();
|
|
}
|
|
}
|
|
|
|
public function saveInto(DataObject $record) {
|
|
$fieldName = $this->name . 'ID';
|
|
$hasOnes = $record->has_one($this->name);
|
|
if(!$hasOnes) $hasOnes = $record->has_one($fieldName);
|
|
|
|
// assume that the file is connected via a has-one
|
|
if( !$hasOnes || !isset($_FILES[$this->name]) || !$_FILES[$this->name]['name']){
|
|
return;
|
|
}
|
|
|
|
$file = new File();
|
|
$file->loadUploaded($_FILES[$this->name]);
|
|
|
|
$record->$fieldName = $file->ID;
|
|
}
|
|
}
|
|
?>
|