Skip to content

Commit

Permalink
ENHANCEMENT: populate FormField:: on the fly based on class name of f…
Browse files Browse the repository at this point in the history
…ield rather than requiring explict definition.
  • Loading branch information
wilr committed Apr 14, 2012
1 parent 907568b commit 07d2d52
Show file tree
Hide file tree
Showing 35 changed files with 270 additions and 219 deletions.
4 changes: 2 additions & 2 deletions css/GridField.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 2 additions & 15 deletions forms/CheckboxField.php
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -65,6 +51,7 @@ function performDisabledTransformation() {

/**
* Readonly version of a checkbox field - "Yes" or "No".
*
* @package forms
* @subpackage fields-basic
*/
Expand Down
7 changes: 2 additions & 5 deletions forms/CheckboxSetField.php
Expand Up @@ -33,11 +33,9 @@
* @subpackage fields-basic
*/
class CheckboxSetField extends OptionsetField {

protected $template = 'CheckboxSetField';

/**
* @var Array
* @var array
*/
protected $defaultItems = array();

Expand Down Expand Up @@ -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());
}

/**
Expand Down Expand Up @@ -288,5 +286,4 @@ function Type() {
function ExtraOptions() {
return FormField::ExtraOptions();
}

}
38 changes: 5 additions & 33 deletions forms/CompositeField.php
@@ -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
*/
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 1 addition & 3 deletions forms/DropdownField.php
Expand Up @@ -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,
Expand Down Expand Up @@ -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() {
Expand Down
23 changes: 0 additions & 23 deletions forms/FieldGroup.php
Expand Up @@ -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
*
Expand Down
9 changes: 5 additions & 4 deletions forms/FileField.php
Expand Up @@ -42,8 +42,6 @@
* @subpackage fields-files
*/
class FileField extends FormField {

protected $template = 'FileField';

/**
* Restrict filesize for either all filetypes
Expand Down Expand Up @@ -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() {
Expand Down
2 changes: 0 additions & 2 deletions forms/FileIFrameField.php
Expand Up @@ -12,8 +12,6 @@
*/
class FileIFrameField extends FileField {

protected $template = 'FileIFrameField';

public static $allowed_actions = array (
'iframe',
'EditFileForm',
Expand Down
7 changes: 4 additions & 3 deletions forms/FormAction.php
Expand Up @@ -20,8 +20,6 @@
*/
class FormAction extends FormField {

protected $template = 'FormAction';

protected $action;

/**
Expand All @@ -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);
}

Expand All @@ -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()) {
Expand Down

0 comments on commit 07d2d52

Please sign in to comment.