From 1a10e8bcf55c02a1efa02bfab0706ede5a94e3ac Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Mon, 2 Jan 2012 17:44:23 +0100 Subject: [PATCH 1/4] API CHANGE Removed $rows and $cols constructor arguments on TextareaField and HtmlEditorField, use setRows() and setCols() instead --- forms/HtmlEditorField.php | 6 ++++-- forms/TextareaField.php | 11 ++++------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/forms/HtmlEditorField.php b/forms/HtmlEditorField.php index 143ca7807..c2a4baad6 100644 --- a/forms/HtmlEditorField.php +++ b/forms/HtmlEditorField.php @@ -19,8 +19,10 @@ class HtmlEditorField extends TextareaField { /** * @see TextareaField::__construct() */ - public function __construct($name, $title = null, $rows = 30, $cols = 20, $value = '', $form = null) { - parent::__construct($name, $title, $rows, $cols, $value, $form); + public function __construct($name, $title = null, $value = '') { + if(count(func_get_args()) > 3) Deprecation::notice('3.0', 'Use setRows() and setCols() instead of constructor arguments'); + + parent::__construct($name, $title, $value); self::include_js(); } diff --git a/forms/TextareaField.php b/forms/TextareaField.php index 504ad71ae..50891a296 100644 --- a/forms/TextareaField.php +++ b/forms/TextareaField.php @@ -31,15 +31,12 @@ class TextareaField extends FormField { * * @param $name Field name * @param $title Field title - * @param $rows The number of rows - * @param $cols The number of columns * @param $value The current value - * @param $form The parent form. Auto-set when the field is placed in a form. */ - function __construct($name, $title = null, $rows = 5, $cols = 20, $value = "", $form = null) { - $this->rows = $rows; - $this->cols = $cols; - parent::__construct($name, $title, $value, $form); + function __construct($name, $title = null, $value = '') { + if(count(func_get_args()) > 3) Deprecation::notice('3.0', 'Use setRows() and setCols() instead of constructor arguments'); + + parent::__construct($name, $title, $value); } function getAttributes() { From 27ec98cfce46021dc5509059f6809446d51b88c0 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Mon, 2 Jan 2012 17:43:36 +0100 Subject: [PATCH 2/4] API CHANGE Removed $rightTitle and $folderName constructor arguments for FileField and SimpleImageField, use setRightTitle() and setFolderName() instead --- forms/FileField.php | 10 ++++------ forms/SimpleImageField.php | 6 ++++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/forms/FileField.php b/forms/FileField.php index d63e7217f..ce53ceab7 100644 --- a/forms/FileField.php +++ b/forms/FileField.php @@ -101,15 +101,13 @@ class FileField extends FormField { * @param string $name The internal field name, passed to forms. * @param string $title The field label. * @param int $value The value of the field. - * @param Form $form Reference to the container form - * @param string $rightTitle Used in SmallFieldHolder() to force a right-aligned label - * @param string $folderName Folder to upload files to */ - function __construct($name, $title = null, $value = null, $form = null, $rightTitle = null, $folderName = null) { - if(isset($folderName)) $this->folderName = $folderName; + function __construct($name, $title = null, $value = null) { + if(count(func_get_args()) > 3) Deprecation::notice('3.0', 'Use setRightTitle() and setFolderName() instead of constructor arguments'); + $this->upload = new Upload(); - parent::__construct($name, $title, $value, $form, $rightTitle); + parent::__construct($name, $title, $value); } public function Field($properties = array()) { diff --git a/forms/SimpleImageField.php b/forms/SimpleImageField.php index 279a9f8c4..6f22e4014 100644 --- a/forms/SimpleImageField.php +++ b/forms/SimpleImageField.php @@ -65,8 +65,10 @@ class SimpleImageField extends FileField { - function __construct($name, $title = null, $value = null, $form = null, $rightTitle = null, $folderName = null) { - parent::__construct($name, $title, $value, $form, $rightTitle, $folderName); + function __construct($name, $title = null, $value = null) { + if(count(func_get_args()) > 3) Deprecation::notice('3.0', 'Use setRightTitle() and setFolderName() instead of constructor arguments'); + + parent::__construct($name, $title, $value); $this->getValidator()->setAllowedExtensions(array('jpg','gif','png')); } From 3c5c04cd755e6a856a8aa61d8c573f966cdabd99 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Mon, 2 Jan 2012 17:45:47 +0100 Subject: [PATCH 3/4] API CHANGE Removed $maxlength constructor argument from PasswordField, use setMaxlength() instead --- forms/PasswordField.php | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/forms/PasswordField.php b/forms/PasswordField.php index 0776e12d7..a76779df9 100644 --- a/forms/PasswordField.php +++ b/forms/PasswordField.php @@ -6,20 +6,13 @@ */ class PasswordField extends TextField { - /** - * maxlength of the password field - * - * @var int - */ - protected $maxLength; - - /** * Returns an input field, class="text" and type="text" with an optional * maxlength */ - function __construct($name, $title = null, $value = "", $maxLength = null) { - $this->maxLength = $maxLength; + function __construct($name, $title = null, $value = "") { + if(count(func_get_args()) > 3) Deprecation::notice('3.0', 'Use setMaxLength() instead of constructor arguments'); + parent::__construct($name, $title, $value); } From cc329574140e171e301babd5ea39d85fe4411dde Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Mon, 2 Jan 2012 17:09:30 +0100 Subject: [PATCH 4/4] 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) --- docs/en/changelogs/3.0.0.md | 8 ++++++++ forms/CountryDropdownField.php | 2 +- forms/DateField.php | 2 +- forms/FormField.php | 4 +--- forms/HeaderField.php | 4 ++-- forms/LabelField.php | 4 ++-- forms/ListboxField.php | 4 ++-- forms/MoneyField.php | 4 ++-- forms/PhoneNumberField.php | 5 ++--- 9 files changed, 21 insertions(+), 16 deletions(-) diff --git a/docs/en/changelogs/3.0.0.md b/docs/en/changelogs/3.0.0.md index bd911ce56..10fc47a47 100644 --- a/docs/en/changelogs/3.0.0.md +++ b/docs/en/changelogs/3.0.0.md @@ -84,6 +84,14 @@ as well as the HTML form element itself. +### 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 ### In order to make the `sapphire` framework useable without the `cms` module, diff --git a/forms/CountryDropdownField.php b/forms/CountryDropdownField.php index e7309972c..6c0d8520e 100644 --- a/forms/CountryDropdownField.php +++ b/forms/CountryDropdownField.php @@ -12,7 +12,7 @@ class CountryDropdownField extends DropdownField { 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(!$value) $value = Geoip::visitor_country(); diff --git a/forms/DateField.php b/forms/DateField.php index b67070368..5b0a91281 100644 --- a/forms/DateField.php +++ b/forms/DateField.php @@ -87,7 +87,7 @@ class DateField extends TextField { */ protected $valueObj = null; - function __construct($name, $title = null, $value = null, $form = null, $rightTitle = null) { + function __construct($name, $title = null, $value = null) { if(!$this->locale) { $this->locale = i18n::get_locale(); } diff --git a/forms/FormField.php b/forms/FormField.php index 0a72df373..ec18696ff 100644 --- a/forms/FormField.php +++ b/forms/FormField.php @@ -100,10 +100,8 @@ class FormField extends RequestHandler { * @param name The internal field name, passed to forms. * @param title The field label. * @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->title = ($title === null) ? $name : $title; diff --git a/forms/HeaderField.php b/forms/HeaderField.php index a8c90fff5..696df8cb1 100644 --- a/forms/HeaderField.php +++ b/forms/HeaderField.php @@ -14,7 +14,7 @@ class HeaderField extends DatalessField { */ 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, ... // instead of new handling: $name, $title, $heading, ... $args = func_get_args(); @@ -29,7 +29,7 @@ class HeaderField extends DatalessField { if($headingLevel) $this->headingLevel = $headingLevel; - parent::__construct($name, $title, null, $form); + parent::__construct($name, $title); } public function getHeadingLevel() { diff --git a/forms/LabelField.php b/forms/LabelField.php index 33d8f00a8..6f6974e35 100644 --- a/forms/LabelField.php +++ b/forms/LabelField.php @@ -16,7 +16,7 @@ class LabelField extends DatalessField { * @param string $title * @param Form $form */ - function __construct($name, $title, $form = null) { + function __construct($name, $title) { // legacy handling for old parameters: $title, $heading, ... // instead of new handling: $name, $title, $heading, ... $args = func_get_args(); @@ -26,7 +26,7 @@ class LabelField extends DatalessField { $form = (isset($args[3])) ? $args[3] : null; } - parent::__construct($name, $title, $form); + parent::__construct($name, $title); } } \ No newline at end of file diff --git a/forms/ListboxField.php b/forms/ListboxField.php index 6c1c42002..43e0b4e37 100644 --- a/forms/ListboxField.php +++ b/forms/ListboxField.php @@ -51,10 +51,10 @@ class ListboxField extends DropdownField { * @param int $size Optional size of the select element * @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($multiple) $this->multiple = $multiple; - parent::__construct($name, $title, $source, $value, $form); + parent::__construct($name, $title, $source, $value); } /** diff --git a/forms/MoneyField.php b/forms/MoneyField.php index f9a54a13d..091f2c3c6 100644 --- a/forms/MoneyField.php +++ b/forms/MoneyField.php @@ -32,12 +32,12 @@ class MoneyField extends FormField { */ 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 $this->fieldAmount = new NumericField("{$name}[Amount]", _t('MoneyField.FIELDLABELAMOUNT', 'Amount')); $this->fieldCurrency = $this->FieldCurrency($name); - parent::__construct($name, $title, $value, $form); + parent::__construct($name, $title, $value); } /** diff --git a/forms/PhoneNumberField.php b/forms/PhoneNumberField.php index 59defb192..9e1493582 100644 --- a/forms/PhoneNumberField.php +++ b/forms/PhoneNumberField.php @@ -17,14 +17,13 @@ class PhoneNumberField extends FormField { protected $countryCode; protected $ext; - public function __construct( $name, $title = null, $value = '', $extension = null, - $areaCode = null, $countryCode = null, $form = null ) { + public function __construct( $name, $title = null, $value = '', $extension = null, $areaCode = null, $countryCode = null) { $this->areaCode = $areaCode; $this->ext = $extension; $this->countryCode = $countryCode; - parent::__construct( $name, $title, $value, $form ); + parent::__construct($name, $title, $value); } public function Field() {