Permalink
Browse files

API CHANGE Add Form->getController() and use this instead of Controll…

…er::curr() in FileIFrameField

API CHANGE Add Form->getName() and deprecate Form->Name(), use getName() instead.
  • Loading branch information...
1 parent 77c2365 commit c7e0cee637943ae81957d90859e58da02c426e27 @halkyon halkyon committed May 23, 2012
Showing with 56 additions and 17 deletions.
  1. +12 −11 forms/FileIFrameField.php
  2. +44 −6 forms/Form.php
@@ -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 @@ public function save($data, $form) {
|| ($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 @@ public function save($data, $form) {
$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 @@ public function save($data, $form) {
// 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 @@ public function save($data, $form) {
}
$this->form->getRecord()->write();
- Controller::curr()->redirectBack();
+ $controller->redirectBack();
}
/**
@@ -255,12 +256,12 @@ public function delete($data, $form) {
$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
@@ -291,7 +291,7 @@ public function httpSubmission($request) {
) {
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 @@ public function setFormAction($path) {
* @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 @@ public function setHTMLID($id) {
}
/**
- * 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.

0 comments on commit c7e0cee

Please sign in to comment.