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

@ -175,11 +175,12 @@ class FileIFrameField extends FileField {
|| ($data['FileSource'] == 'existing' && (!isset($data['ExistingFile']) || !$data['ExistingFile'])) || ($data['FileSource'] == 'existing' && (!isset($data['ExistingFile']) || !$data['ExistingFile']))
) { ) {
$form->sessionMessage(_t('FileIFrameField.NOSOURCE', 'Please select a source file to attach'), 'required'); $form->sessionMessage(_t('FileIFrameField.NOSOURCE', 'Please select a source file to attach'), 'required');
Controller::curr()->redirectBack(); $form->getController()->redirectBack();
return; return;
} }
$desiredClass = $this->dataClass(); $desiredClass = $this->dataClass();
$controller = $this->form->getController();
// upload a new file // upload a new file
if($data['FileSource'] == 'new') { if($data['FileSource'] == 'new') {
@ -189,12 +190,12 @@ class FileIFrameField extends FileField {
$this->upload->loadIntoFile($_FILES['Upload'], $fileObject, $this->folderName); $this->upload->loadIntoFile($_FILES['Upload'], $fileObject, $this->folderName);
} catch (Exception $e){ } catch (Exception $e){
$form->sessionMessage(_t('FileIFrameField.DISALLOWEDFILETYPE', 'This filetype is not allowed to be uploaded'), 'bad'); $form->sessionMessage(_t('FileIFrameField.DISALLOWEDFILETYPE', 'This filetype is not allowed to be uploaded'), 'bad');
Controller::curr()->redirectBack(); $controller->redirectBack();
return; return;
} }
if($this->upload->isError()) { if($this->upload->isError()) {
Controller::curr()->redirectBack(); $controller->redirectBack();
return; return;
} }
@ -209,7 +210,7 @@ class FileIFrameField extends FileField {
// dont allow the user to attach a folder by default // dont allow the user to attach a folder by default
if(!$fileObject || ($fileObject instanceof Folder && $desiredClass != 'Folder')) { if(!$fileObject || ($fileObject instanceof Folder && $desiredClass != 'Folder')) {
Controller::curr()->redirectBack(); $controller->redirectBack();
return; return;
} }
@ -222,7 +223,7 @@ class FileIFrameField extends FileField {
} }
$this->form->getRecord()->write(); $this->form->getRecord()->write();
Controller::curr()->redirectBack(); $controller->redirectBack();
} }
/** /**
@ -260,7 +261,7 @@ class FileIFrameField extends FileField {
$this->form->getRecord()->{$this->getName() . 'ID'} = 0; $this->form->getRecord()->{$this->getName() . 'ID'} = 0;
$this->form->getRecord()->write(); $this->form->getRecord()->write();
Controller::curr()->redirectBack(); $this->form->getController()->redirectBack();
} }
/** /**

View File

@ -291,7 +291,7 @@ class Form extends RequestHandler {
) { ) {
return $this->httpError( return $this->httpError(
403, 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) // TODO : Once we switch to a stricter policy regarding allowed_actions (meaning actions must be set explicitly in allowed_actions in order to run)
@ -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() { public function Controller() {
return $this->getController();
}
/**
* Get the controller.
* @return Controller
*/
public function getController() {
return $this->controller; return $this->controller;
} }
/**
* Set the controller.
* @param Controller $controller
* @return Form
*/
public function setController($controller) {
$this->controller = $controller;
return $this;
}
/** /**
* @return string * @return string
*/ */
public function Name() { 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; 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. * 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. * That method will return the field itself.