Permalink
Browse files

ENHANCEMENT: populate FormField:: on the fly based on class name of f…

…ield rather than requiring explict definition.
  • Loading branch information...
wilr committed Apr 14, 2012
1 parent 907568b commit 07d2d5273ac890e9a5ea81a4bf83b5ef001e3bb6
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -1,15 +1,12 @@
<?php
/**
* Single checkbox field.
+ *
* @package forms
* @subpackage fields-basic
*/
class CheckboxField extends FormField {
- protected $template = 'CheckboxField';
-
- protected $fieldHolderTemplate = 'CheckboxFieldHolder';
-
function setValue($value) {
$this->value = ($value) ? 1 : 0;
return $this;
@@ -23,17 +20,6 @@ function Value() {
return ($this->value) ? 1 : 0;
}
- /**
- * Returns a restricted field holder used within things like FieldGroups
- */
- function SmallFieldHolder() {
- $result = $this->Field();
- if($t = $this->Title()) {
- $result .= "<label for=\"" . $this->id() ."\">$t</label> ";
- }
- return $result;
- }
-
function getAttributes() {
$attrs = parent::getAttributes();
$attrs['value'] = 1;
@@ -65,6 +51,7 @@ function performDisabledTransformation() {
/**
* Readonly version of a checkbox field - "Yes" or "No".
+ *
* @package forms
* @subpackage fields-basic
*/
@@ -33,11 +33,9 @@
* @subpackage fields-basic
*/
class CheckboxSetField extends OptionsetField {
-
- protected $template = 'CheckboxSetField';
/**
- * @var Array
+ * @var array
*/
protected $defaultItems = array();
@@ -130,7 +128,7 @@ function Field($properties = array()) {
$properties = array_merge($properties, array('Options' => new ArrayList($options)));
- return $this->customise($properties)->renderWith($this->getTemplate());
+ return $this->customise($properties)->renderWith($this->getTemplates());
}
/**
@@ -288,5 +286,4 @@ function Type() {
function ExtraOptions() {
return FormField::ExtraOptions();
}
-
}
View
@@ -1,8 +1,11 @@
<?php
/**
* Base class for all fields that contain other fields.
- * Implements sequentialisation - so that when we're saving / loading data, we can populate
- * a tabbed form properly. All of the children are stored in $this->children
+ *
+ * Implements sequentialisation - so that when we're saving / loading data, we
+ * can populate a tabbed form properly. All of the children are stored in
+ * $this->children
+ *
* @package forms
* @subpackage fields-structural
*/
@@ -33,11 +36,6 @@ class CompositeField extends FormField {
*/
protected $tag = 'div';
- /**
- * @var string
- */
- protected $template = "CompositeField";
-
/**
* @var String Optional description for this set of fields.
* If the {@link $tag} property is set to use a 'fieldset', this will be
@@ -152,32 +150,6 @@ function getAttributes() {
);
}
- public function Field($properties = array()) {
- $props = $this->customise($properties);
-
- return $props->renderWith($this->getTemplate());
- }
-
- /**
- * @param array
- */
- function FieldHolder($properties = array()) {
- $props = $this->customise($properties);
-
- return $props->renderWith($this->getTemplate());
- }
-
- /**
- * Returns the fields in the restricted field holder.
- *
- * @param array
- */
- function SmallFieldHolder($properties = array()) {
- $obj = ($properties) ? $this->customise($properties) : $this;
-
- return $obj->renderWith($this->getTemplate());
- }
-
/**
* Add all of the non-composite fields contained within this field to the
* list.
View
@@ -75,8 +75,6 @@
* @subpackage fields-basic
*/
class DropdownField extends FormField {
-
- protected $template = 'DropdownField';
/**
* @var boolean $source Associative or numeric array of all dropdown items,
@@ -158,7 +156,7 @@ function Field($properties = array()) {
$properties = array_merge($properties, array('Options' => new ArrayList($options)));
- return $this->customise($properties)->renderWith($this->getTemplate());
+ return parent::Field($properties);
}
function getAttributes() {
View
@@ -85,29 +85,6 @@ function Name(){
return preg_replace("/[^a-zA-Z0-9]+/", "", $this->title);
}
-
- /**
- * Generates the field HTML with the HTML for child {@link FormField}
- *
- * @param array $properties custom properties for the template
- */
- function Field($properties = array()) {
- $props = $this->customise(new ArrayData($properties));
-
- return $props->renderWith('FieldGroupField');
- }
-
- /**
- * Generates the field HTML with the HTML for child {@link FormField}
- *
- * @param array $properties custom properties for the template
- */
- function FieldHolder($properties = array()) {
- $props = $this->customise(new ArrayData($properties));
-
- return $props->renderWith('FieldGroupHolder');
- }
-
/**
* Set an odd/even class
*
View
@@ -42,8 +42,6 @@
* @subpackage fields-files
*/
class FileField extends FormField {
-
- protected $template = 'FileField';
/**
* Restrict filesize for either all filetypes
@@ -112,8 +110,11 @@ function __construct($name, $title = null, $value = null) {
}
public function Field($properties = array()) {
- $properties = array_merge($properties, array('MaxFileSize' => $this->getValidator()->getAllowedMaxFileSize()));
- return $this->customise($properties)->renderWith($this->getTemplate());
+ $properties = array_merge($properties, array(
+ 'MaxFileSize' => $this->getValidator()->getAllowedMaxFileSize()
+ ));
+
+ return parent::Field($properties);
}
function getAttributes() {
@@ -12,8 +12,6 @@
*/
class FileIFrameField extends FileField {
- protected $template = 'FileIFrameField';
-
public static $allowed_actions = array (
'iframe',
'EditFileForm',
View
@@ -20,8 +20,6 @@
*/
class FormAction extends FormField {
- protected $template = 'FormAction';
-
protected $action;
/**
@@ -36,12 +34,14 @@ class FormAction extends FormField {
/**
* Create a new action button.
+ *
* @param action The method to call when the button is clicked
* @param title The label on the button
* @param form The parent form, auto-set when the field is placed inside a form
*/
function __construct($action, $title = "", $form = null) {
$this->action = "action_$action";
+
parent::__construct($this->action, $title, null, $form);
}
@@ -67,7 +67,8 @@ function Field($properties = array()) {
'UseButtonTag' => $this->useButtonTag
)
);
- return $this->customise($properties)->renderWith($this->getTemplate());
+
+ return parent::Field($properties);
}
function FieldHolder($properties = array()) {
Oops, something went wrong.

0 comments on commit 07d2d52

Please sign in to comment.