Defined $schemaDataType constant, added to FormField subclasses

This commit is contained in:
Ingo Schommer 2016-03-21 23:12:23 +13:00
parent 3862a7a0a7
commit 55f12939bb
17 changed files with 75 additions and 5 deletions

View File

@ -7,6 +7,8 @@
*/
class CheckboxField extends FormField {
protected $schemaDataType = FormField::SCHEMA_DATA_TYPE_SINGLESELECT;
public function setValue($value) {
$this->value = ($value) ? 1 : 0;
return $this;

View File

@ -38,6 +38,8 @@
*/
class CheckboxSetField extends MultiSelectField {
protected $schemaDataType = FormField::SCHEMA_DATA_TYPE_MULTISELECT;
/**
* @todo Explain different source data that can be used with this field,
* e.g. SQLMap, ArrayList or an array.

View File

@ -43,6 +43,8 @@ class CompositeField extends FormField {
*/
protected $legend;
protected $schemaDataType = FormField::SCHEMA_DATA_TYPE_STRUCTURAL;
public function __construct($children = null) {
if($children instanceof FieldList) {
$this->children = $children;
@ -394,4 +396,3 @@ class CompositeField extends FormField {
}
}

View File

@ -75,6 +75,8 @@ class ConfirmedPasswordField extends FormField {
*/
public $children;
protected $schemaDataType = FormField::SCHEMA_DATA_TYPE_STRUCTURAL;
/**
* @param string $name
* @param string $title

View File

@ -28,6 +28,8 @@ class CountryDropdownField extends DropdownField {
protected $extraClasses = array('dropdown');
protected $schemaDataType = FormField::SCHEMA_DATA_TYPE_SINGLESELECT;
/**
* Get the locale of the Member, or if we're not logged in or don't have a locale, use the default one
* @return string

View File

@ -112,4 +112,3 @@ class CurrencyField_Disabled extends CurrencyField{
. " name=\"".$this->name."\" value=\"".$valforInput."\" />";
}
}

View File

@ -60,6 +60,8 @@ require_once 'Zend/Date.php';
*/
class DateField extends TextField {
protected $schemaDataType = FormField::SCHEMA_DATA_TYPE_DATE;
/**
* @config
* @var array
@ -677,4 +679,3 @@ class DateField_View_JQuery extends Object {
return preg_replace($patterns, $replacements, $format);
}
}

View File

@ -44,6 +44,8 @@ class DatetimeField extends FormField {
*/
protected $timeField = null;
protected $schemaDataType = FormField::SCHEMA_DATA_TYPE_DATETIME;
/**
* @config
* @var array

View File

@ -29,6 +29,48 @@
*/
class FormField extends RequestHandler {
/** @see $schemaDataType */
const SCHEMA_DATA_TYPE_STRING = 'String';
/** @see $schemaDataType */
const SCHEMA_DATA_TYPE_HIDDEN = 'Hidden';
/** @see $schemaDataType */
const SCHEMA_DATA_TYPE_TEXT = 'Text';
/** @see $schemaDataType */
const SCHEMA_DATA_TYPE_HTML = 'HTML';
/** @see $schemaDataType */
const SCHEMA_DATA_TYPE_INTEGER = 'Integer';
/** @see $schemaDataType */
const SCHEMA_DATA_TYPE_DECIMAL = 'Decimal';
/** @see $schemaDataType */
const SCHEMA_DATA_TYPE_MULTISELECT = 'MultiSelect';
/** @see $schemaDataType */
const SCHEMA_DATA_TYPE_SINGLESELECT = 'SingleSelect';
/** @see $schemaDataType */
const SCHEMA_DATA_TYPE_DATE = 'Date';
/** @see $schemaDataType */
const SCHEMA_DATA_TYPE_DATETIME = 'DateTime';
/** @see $schemaDataType */
const SCHEMA_DATA_TYPE_TIME = 'Time';
/** @see $schemaDataType */
const SCHEMA_DATA_TYPE_BOOLEAN = 'Boolean';
/** @see $schemaDataType */
const SCHEMA_DATA_TYPE_CUSTOM = 'Custom';
/** @see $schemaDataType */
const SCHEMA_DATA_TYPE_STRUCTURAL = 'Structural';
/**
* @var Form
*/
@ -170,7 +212,7 @@ class FormField extends RequestHandler {
/**
* The data type backing the field. Represents the type of value the
* form expects to receive via a postback.
* form expects to receive via a postback. Should be set in subclasses.
*
* The values allowed in this list include:
*
@ -192,6 +234,8 @@ class FormField extends RequestHandler {
* or simply be a block of stand-alone content. As with 'Custom',
* the component property is mandatory if this is assigned.
*
* Each value has an equivalent constant, e.g. {@link self::SCHEMA_DATA_TYPE_STRING}.
*
* @var string
*/
protected $schemaDataType;

View File

@ -7,6 +7,9 @@
* @subpackage fields-dataless
*/
class HiddenField extends FormField {
protected $schemaDataType = FormField::SCHEMA_DATA_TYPE_HIDDEN;
/**
* @param array $properties
*

View File

@ -15,6 +15,8 @@ use SilverStripe\Model\FieldType\DBMoney;
*/
class MoneyField extends FormField {
protected $schemaDataType = FormField::SCHEMA_DATA_TYPE_TEXT;
/**
* @var string $_locale
*/

View File

@ -15,6 +15,8 @@ abstract class MultiSelectField extends SelectField {
*/
protected $defaultItems = array();
protected $schemaDataType = FormField::SCHEMA_DATA_TYPE_MULTISELECT;
/**
* Extracts the value of this field, normalised as an array.
* Scalar values will return a single length array, even if empty

View File

@ -9,6 +9,9 @@
* @subpackage fields-formattedinput
*/
class NumericField extends TextField {
protected $schemaDataType = FormField::SCHEMA_DATA_TYPE_DECIMAL;
/**
* Override locale for this field.
*

View File

@ -23,6 +23,8 @@ abstract class SingleSelectField extends SelectField {
*/
protected $emptyString = '';
protected $schemaDataType = FormField::SCHEMA_DATA_TYPE_SINGLESELECT;
/**
* @param boolean $bool
* @return self Self reference

View File

@ -82,4 +82,3 @@ class Tab extends CompositeField {
);
}
}

View File

@ -12,6 +12,8 @@ class TextField extends FormField {
*/
protected $maxLength;
protected $schemaDataType = FormField::SCHEMA_DATA_TYPE_TEXT;
/**
* Returns an input field.
*

View File

@ -50,6 +50,8 @@ class TimeField extends TextField {
*/
protected $valueObj = null;
protected $schemaDataType = FormField::SCHEMA_DATA_TYPE_TIME;
public function __construct($name, $title = null, $value = ""){
if(!$this->locale) {
$this->locale = i18n::get_locale();