API CHANGE Don't allow specifying $form as constructor argument in various form fields, use setForm() instead (to achieve a cleaner API with less confusing parameter order)

This commit is contained in:
Ingo Schommer 2012-01-02 17:09:30 +01:00
parent 3c5c04cd75
commit cc32957414
9 changed files with 21 additions and 16 deletions

View File

@ -84,6 +84,14 @@ as well as the HTML form element itself.
<input type="checkbox" class="checkbox extraClass".../> <input type="checkbox" class="checkbox extraClass".../>
</div> </div>
### FormField constructor argument changes ###
In order to enforce a consistent parameter order in core [api:FormField] subclasses,
its no longer possible to set the following optional attributes via constructor arguments:
`$form`, `$maxLength`, `$rightTitle`, `$rows`/`$cols` (for `TextareaField` and `HtmlEditorField`)
and `$folderName` (for `FileField` and `SimpleImageField`).
Please use the appropriate setters on the form field instance instead.
### Restructured files and folders ### ### Restructured files and folders ###
In order to make the `sapphire` framework useable without the `cms` module, In order to make the `sapphire` framework useable without the `cms` module,

View File

@ -12,7 +12,7 @@ class CountryDropdownField extends DropdownField {
protected $defaultToVisitorCountry = true; protected $defaultToVisitorCountry = true;
function __construct($name, $title = null, $source = null, $value = "", $form=null) { function __construct($name, $title = null, $source = null, $value = "") {
if(!is_array($source)) $source = Geoip::getCountryDropDown(); if(!is_array($source)) $source = Geoip::getCountryDropDown();
if(!$value) $value = Geoip::visitor_country(); if(!$value) $value = Geoip::visitor_country();

View File

@ -87,7 +87,7 @@ class DateField extends TextField {
*/ */
protected $valueObj = null; protected $valueObj = null;
function __construct($name, $title = null, $value = null, $form = null, $rightTitle = null) { function __construct($name, $title = null, $value = null) {
if(!$this->locale) { if(!$this->locale) {
$this->locale = i18n::get_locale(); $this->locale = i18n::get_locale();
} }

View File

@ -100,10 +100,8 @@ class FormField extends RequestHandler {
* @param name The internal field name, passed to forms. * @param name The internal field name, passed to forms.
* @param title The field label. * @param title The field label.
* @param value The value of the field. * @param value The value of the field.
* @param form Reference to the container form
* @param maxLength The Maximum length of the attribute
*/ */
function __construct($name, $title = null, $value = null, $form = null, $rightTitle = null) { function __construct($name, $title = null, $value = null) {
$this->name = $name; $this->name = $name;
$this->title = ($title === null) ? $name : $title; $this->title = ($title === null) ? $name : $title;

View File

@ -14,7 +14,7 @@ class HeaderField extends DatalessField {
*/ */
protected $headingLevel = 2; protected $headingLevel = 2;
function __construct($name, $title = null, $headingLevel = 2, $form = null) { function __construct($name, $title = null, $headingLevel = 2) {
// legacy handling for old parameters: $title, $heading, ... // legacy handling for old parameters: $title, $heading, ...
// instead of new handling: $name, $title, $heading, ... // instead of new handling: $name, $title, $heading, ...
$args = func_get_args(); $args = func_get_args();
@ -29,7 +29,7 @@ class HeaderField extends DatalessField {
if($headingLevel) $this->headingLevel = $headingLevel; if($headingLevel) $this->headingLevel = $headingLevel;
parent::__construct($name, $title, null, $form); parent::__construct($name, $title);
} }
public function getHeadingLevel() { public function getHeadingLevel() {

View File

@ -16,7 +16,7 @@ class LabelField extends DatalessField {
* @param string $title * @param string $title
* @param Form $form * @param Form $form
*/ */
function __construct($name, $title, $form = null) { function __construct($name, $title) {
// legacy handling for old parameters: $title, $heading, ... // legacy handling for old parameters: $title, $heading, ...
// instead of new handling: $name, $title, $heading, ... // instead of new handling: $name, $title, $heading, ...
$args = func_get_args(); $args = func_get_args();
@ -26,7 +26,7 @@ class LabelField extends DatalessField {
$form = (isset($args[3])) ? $args[3] : null; $form = (isset($args[3])) ? $args[3] : null;
} }
parent::__construct($name, $title, $form); parent::__construct($name, $title);
} }
} }

View File

@ -51,10 +51,10 @@ class ListboxField extends DropdownField {
* @param int $size Optional size of the select element * @param int $size Optional size of the select element
* @param form The parent form * @param form The parent form
*/ */
function __construct($name, $title = '', $source = array(), $value = '', $size = null, $multiple = false, $form = null) { function __construct($name, $title = '', $source = array(), $value = '', $size = null, $multiple = false) {
if($size) $this->size = $size; if($size) $this->size = $size;
if($multiple) $this->multiple = $multiple; if($multiple) $this->multiple = $multiple;
parent::__construct($name, $title, $source, $value, $form); parent::__construct($name, $title, $source, $value);
} }
/** /**

View File

@ -32,12 +32,12 @@ class MoneyField extends FormField {
*/ */
protected $fieldCurrency = null; protected $fieldCurrency = null;
function __construct($name, $title = null, $value = "", $form = null) { function __construct($name, $title = null, $value = "") {
// naming with underscores to prevent values from actually being saved somewhere // naming with underscores to prevent values from actually being saved somewhere
$this->fieldAmount = new NumericField("{$name}[Amount]", _t('MoneyField.FIELDLABELAMOUNT', 'Amount')); $this->fieldAmount = new NumericField("{$name}[Amount]", _t('MoneyField.FIELDLABELAMOUNT', 'Amount'));
$this->fieldCurrency = $this->FieldCurrency($name); $this->fieldCurrency = $this->FieldCurrency($name);
parent::__construct($name, $title, $value, $form); parent::__construct($name, $title, $value);
} }
/** /**

View File

@ -17,14 +17,13 @@ class PhoneNumberField extends FormField {
protected $countryCode; protected $countryCode;
protected $ext; protected $ext;
public function __construct( $name, $title = null, $value = '', $extension = null, public function __construct( $name, $title = null, $value = '', $extension = null, $areaCode = null, $countryCode = null) {
$areaCode = null, $countryCode = null, $form = null ) {
$this->areaCode = $areaCode; $this->areaCode = $areaCode;
$this->ext = $extension; $this->ext = $extension;
$this->countryCode = $countryCode; $this->countryCode = $countryCode;
parent::__construct( $name, $title, $value, $form ); parent::__construct($name, $title, $value);
} }
public function Field() { public function Field() {