API CHANGE Add Form->getController() and use this instead of Controller::curr() in FileIFrameField

API CHANGE Add Form->getName() and deprecate Form->Name(), use getName() instead.
This commit is contained in:
Sean Harvey 2012-05-24 10:33:40 +12:00
parent 77c2365b87
commit c7e0cee637
2 changed files with 56 additions and 17 deletions

View File

@ -1,4 +1,4 @@
<?php
<?php
/**
* A field that allows you to attach a file to a DataObject without submitting the form it is part of, through the use
* of an iframe.
@ -175,12 +175,13 @@ class FileIFrameField extends FileField {
|| ($data['FileSource'] == 'existing' && (!isset($data['ExistingFile']) || !$data['ExistingFile']))
) {
$form->sessionMessage(_t('FileIFrameField.NOSOURCE', 'Please select a source file to attach'), 'required');
Controller::curr()->redirectBack();
$form->getController()->redirectBack();
return;
}
$desiredClass = $this->dataClass();
$controller = $this->form->getController();
// upload a new file
if($data['FileSource'] == 'new') {
$fileObject = Object::create($desiredClass);
@ -189,12 +190,12 @@ class FileIFrameField extends FileField {
$this->upload->loadIntoFile($_FILES['Upload'], $fileObject, $this->folderName);
} catch (Exception $e){
$form->sessionMessage(_t('FileIFrameField.DISALLOWEDFILETYPE', 'This filetype is not allowed to be uploaded'), 'bad');
Controller::curr()->redirectBack();
$controller->redirectBack();
return;
}
if($this->upload->isError()) {
Controller::curr()->redirectBack();
$controller->redirectBack();
return;
}
@ -209,7 +210,7 @@ class FileIFrameField extends FileField {
// dont allow the user to attach a folder by default
if(!$fileObject || ($fileObject instanceof Folder && $desiredClass != 'Folder')) {
Controller::curr()->redirectBack();
$controller->redirectBack();
return;
}
@ -222,7 +223,7 @@ class FileIFrameField extends FileField {
}
$this->form->getRecord()->write();
Controller::curr()->redirectBack();
$controller->redirectBack();
}
/**
@ -255,12 +256,12 @@ class FileIFrameField extends FileField {
$file->delete();
}
}
// then un-attach file from this record
$this->form->getRecord()->{$this->getName() . 'ID'} = 0;
$this->form->getRecord()->write();
Controller::curr()->redirectBack();
$this->form->getController()->redirectBack();
}
/**

View File

@ -291,7 +291,7 @@ class Form extends RequestHandler {
) {
return $this->httpError(
403,
sprintf('Action "%s" not allowed on form (Name: "%s")', $funcName, $this->Name())
sprintf('Action "%s" not allowed on form (Name: "%s")', $funcName, $this->name)
);
}
// TODO : Once we switch to a stricter policy regarding allowed_actions (meaning actions must be set explicitly in allowed_actions in order to run)
@ -871,13 +871,13 @@ class Form extends RequestHandler {
* @ignore
*/
private $htmlID = null;
/**
* Returns the name of the form
*/
public function FormName() {
if($this->htmlID) return $this->htmlID;
else return $this->class . '_' . str_replace(array('.','/'),'',$this->name);
else return $this->class . '_' . str_replace(array('.', '/'), '', $this->name);
}
/**
@ -888,19 +888,57 @@ class Form extends RequestHandler {
}
/**
* Returns this form's controller
* Returns this form's controller.
* This is used in the templates.
*/
public function Controller() {
return $this->getController();
}
/**
* Get the controller.
* @return Controller
*/
public function getController() {
return $this->controller;
}
/**
* Set the controller.
* @param Controller $controller
* @return Form
*/
public function setController($controller) {
$this->controller = $controller;
return $this;
}
/**
* @return string
*/
public function Name() {
Deprecation::notice('3.0', 'Use getName() instead.');
return $this->getName();
}
/**
* Get the name of the form.
* @return string
*/
public function getName() {
return $this->name;
}
/**
* Set the name of the form.
* @param string $name
* @return Form
*/
public function setName($name) {
$this->name = $name;
return $this;
}
/**
* Returns an object where there is a method with the same name as each data field on the form.
* That method will return the field itself.