Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

ENHANCEMENT Fluent interface in Form API by returning instance from a…

…ll setters
  • Loading branch information...
commit 7602d081a2523908569b1b3401e6240e81ab117d 1 parent f2717f0
@chillu chillu authored
View
1  forms/CheckboxField.php
@@ -12,6 +12,7 @@ class CheckboxField extends FormField {
function setValue($value) {
$this->value = ($value) ? 1 : 0;
+ return $this;
}
function dataValue() {
View
4 forms/CheckboxSetField.php
@@ -135,6 +135,7 @@ function Field($properties = array()) {
function setDisabled($val) {
$this->disabled = $val;
+ return $this;
}
/**
@@ -146,6 +147,7 @@ function setDisabled($val) {
*/
function setDefaultItems($items) {
$this->defaultItems = $items;
+ return $this;
}
/**
@@ -166,6 +168,8 @@ function setValue($value, $obj = null) {
}
parent::setValue($value, $obj);
+
+ return $this;
}
/**
View
3  forms/ComplexTableField.php
@@ -340,10 +340,12 @@ function createFieldList() {
function setController($controller) {
$this->controller = $controller;
+ return $this;
}
function setTemplatePopup($template) {
$this->templatePopup = $template;
+ return $this;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -448,6 +450,7 @@ function AddForm($childID = null) {
*/
function setRelationAutoSetting($value) {
Deprecation::notice('3.0', 'Manipulate the DataList instead.');
+ return $this;
}
/**
View
13 forms/CompositeField.php
@@ -62,6 +62,7 @@ public function FieldSet() {
public function setID($id) {
$this->id = $id;
+ return $this;
}
public function Field() {
@@ -81,6 +82,7 @@ public function getChildren() {
*/
public function setChildren($children) {
$this->children = $children;
+ return $this;
}
function extraClasses() {
@@ -165,14 +167,21 @@ public function collateDataFields(&$list, $saveableOnly = false) {
function setForm($form) {
foreach($this->children as $f) if(is_object($f)) $f->setForm($form);
parent::setForm($form);
+ return $this;
}
function setColumnCount($columnCount) {
$this->columnCount = $columnCount;
+ return $this;
}
- function isComposite() { return true; }
- function hasData() { return false; }
+ function isComposite() {
+ return true;
+ }
+
+ function hasData() {
+ return false;
+ }
public function fieldByName($name) {
return $this->children->fieldByName($name);
View
6 forms/ConfirmedPasswordField.php
@@ -138,6 +138,7 @@ function Field() {
*/
function setCanBeEmpty($value) {
$this->canBeEmpty = (bool)$value;
+ return $this;
}
/**
@@ -149,6 +150,7 @@ function setCanBeEmpty($value) {
*/
public function setShowOnClickTitle($title) {
$this->showOnClickTitle = $title;
+ return $this;
}
/**
@@ -162,6 +164,7 @@ function setRightTitle($title) {
foreach($this->children as $field) {
$field->setRightTitle($title);
}
+ return $this;
}
/**
@@ -176,6 +179,7 @@ function setChildrenTitles($titles) {
}
}
}
+ return $this;
}
/**
@@ -196,6 +200,8 @@ function setValue($value) {
}
$this->children->fieldByName($this->getName() . '[_Password]')->setValue($this->value);
$this->children->fieldByName($this->getName() . '[_ConfirmPassword]')->setValue($this->value);
+
+ return $this;
}
function jsValidation() {
View
1  forms/CurrencyField.php
@@ -15,6 +15,7 @@ class CurrencyField extends TextField {
function setValue($val) {
if(!$val) $val = 0.00;
$this->value = '$' . number_format((double)preg_replace('/[^0-9.\-]/', '', $val), 2);
+ return $this;
}
/**
* Overwrite the datavalue before saving to the db ;-)
View
1  forms/DatalessField.php
@@ -58,6 +58,7 @@ function performReadonlyTransformation() {
*/
function setAllowHTML($bool) {
$this->allowHTML = $bool;
+ return $this;
}
/**
View
4 forms/DateField.php
@@ -229,6 +229,8 @@ function setValue($val) {
}
}
}
+
+ return $this;
}
/**
@@ -470,6 +472,7 @@ function getLocale() {
*/
function setLocale($locale) {
$this->locale = $locale;
+ return $this;
}
/**
@@ -493,6 +496,7 @@ function setConfig($name, $val) {
}
$this->config[$name] = $val;
+ return $this;
}
/**
View
9 forms/DatetimeField.php
@@ -70,6 +70,8 @@ function setForm($form) {
$this->dateField->setForm($form);
$this->timeField->setForm($form);
$this->timezoneField->setForm($form);
+
+ return $this;
}
function FieldHolder() {
@@ -172,6 +174,8 @@ function setValue($val) {
$this->timeField->setValue($valueObj->get($this->timeField->getConfig('timeformat'), $this->locale));
}
}
+
+ return $this;
}
function Value() {
@@ -187,6 +191,7 @@ function setDisabled($bool) {
$this->dateField->setDisabled($bool);
$this->timeField->setDisabled($bool);
if($this->timezoneField) $this->timezoneField->setDisabled($bool);
+ return $this;
}
function setReadonly($bool) {
@@ -194,6 +199,7 @@ function setReadonly($bool) {
$this->dateField->setReadonly($bool);
$this->timeField->setReadonly($bool);
if($this->timezoneField) $this->timezoneField->setReadonly($bool);
+ return $this;
}
/**
@@ -220,6 +226,7 @@ function getTimezoneField() {
function setLocale($locale) {
$this->dateField->setLocale($locale);
$this->timeField->setLocale($locale);
+ return $this;
}
function getLocale() {
@@ -240,6 +247,8 @@ function setConfig($name, $val) {
$this->timezoneField->setValue($val);
$this->setValue($this->dataValue());
}
+
+ return $this;
}
/**
View
4 forms/DropdownField.php
@@ -194,6 +194,7 @@ function getSource() {
*/
function setSource($source) {
$this->source = $source;
+ return $this;
}
/**
@@ -201,6 +202,7 @@ function setSource($source) {
*/
function setHasEmptyDefault($bool) {
$this->hasEmptyDefault = $bool;
+ return $this;
}
/**
@@ -220,6 +222,7 @@ function getHasEmptyDefault() {
function setEmptyString($str) {
$this->setHasEmptyDefault(true);
$this->emptyString = $str;
+ return $this;
}
/**
@@ -242,5 +245,6 @@ function performReadonlyTransformation() {
*/
function setDisabled($disabled = true) {
$this->disabled = $disabled;
+ return $this;
}
}
View
1  forms/FieldGroup.php
@@ -121,6 +121,7 @@ public function setID($id) {
function setZebra($zebra) {
if($zebra == 'odd' || $zebra == 'even') $this->zebra = $zebra;
else user_error("setZebra passed '$zebra'. It should be passed 'odd' or 'even'", E_USER_WARNING);
+ return $this;
}
function FieldHolder() {
View
3  forms/FieldList.php
@@ -401,6 +401,7 @@ protected function onBeforeInsert($item) {
*/
public function setForm($form) {
foreach($this as $field) $field->setForm($form);
+ return $this;
}
/**
@@ -413,6 +414,7 @@ public function setValues($data) {
$fieldName = $field->getName();
if(isset($data[$fieldName])) $field->setValue($data[$fieldName]);
}
+ return $this;
}
/**
@@ -458,6 +460,7 @@ function rootFieldSet() {
function setContainerField($field) {
$this->containerField = $field;
+ return $this;
}
/**
View
20 forms/Form.php
@@ -424,6 +424,7 @@ function makeReadonly() {
*/
public function setRedirectToFormOnValidationError($bool) {
$this->redirectToFormOnValidationError = $bool;
+ return $this;
}
/**
@@ -483,6 +484,7 @@ function setValidator( Validator $validator ) {
$this->validator = $validator;
$this->validator->setForm($this);
}
+ return $this;
}
/**
@@ -562,6 +564,7 @@ function HiddenFields() {
*/
function setFields($fields) {
$this->fields = $fields;
+ return $this;
}
/**
@@ -598,6 +601,7 @@ function Actions() {
*/
function setActions($actions) {
$this->actions = $actions;
+ return $this;
}
/**
@@ -605,6 +609,7 @@ function setActions($actions) {
*/
function unsetAllActions(){
$this->actions = new FieldList();
+ return $this;
}
/**
@@ -625,6 +630,7 @@ function unsetActionByName($name) {
*/
function setAttribute($name, $value) {
$this->attributes[$name] = $value;
+ return $this;
}
/**
@@ -723,6 +729,7 @@ function FormAttributes() {
*/
function setTarget($target) {
$this->target = $target;
+ return $this;
}
/**
@@ -731,6 +738,7 @@ function setTarget($target) {
*/
function setLegend($legend) {
$this->legend = $legend;
+ return $this;
}
/**
@@ -741,6 +749,7 @@ function setLegend($legend) {
*/
function setTemplate($template) {
$this->template = $template;
+ return $this;
}
/**
@@ -784,6 +793,7 @@ public function getEncType() {
*/
public function setEncType($encType) {
$this->encType = $encType;
+ return $this;
}
/**
@@ -831,6 +841,7 @@ function FormMethod() {
*/
function setFormMethod($method) {
$this->formMethod = strtolower($method);
+ return $this;
}
/**
@@ -860,6 +871,7 @@ function FormAction() {
*/
function setFormAction($path) {
$this->formActionPath = $path;
+ return $this;
}
/**
@@ -947,6 +959,7 @@ protected function getMessageFromSession() {
function setMessage($message, $type) {
$this->message = $message;
$this->messageType = $type;
+ return $this;
}
/**
@@ -1283,6 +1296,7 @@ function renderWithoutActionButton($template) {
*/
function setButtonClicked($funcName) {
$this->buttonClickedFunc = $funcName;
+ return $this;
}
function buttonClicked() {
@@ -1306,6 +1320,7 @@ function defaultAction() {
*/
function disableDefaultAction() {
$this->hasDefaultAction = false;
+ return $this;
}
/**
@@ -1317,6 +1332,7 @@ function disableDefaultAction() {
*/
function disableSecurityToken() {
$this->securityToken = new NullSecurityToken();
+ return $this;
}
/**
@@ -1326,6 +1342,7 @@ function disableSecurityToken() {
*/
function enableSecurityToken() {
$this->securityToken = new SecurityToken();
+ return $this;
}
/**
@@ -1417,6 +1434,8 @@ function addExtraClass($class) {
$this->extraClasses[] = $value;
}
+
+ return $this;
}
/**
@@ -1428,6 +1447,7 @@ function addExtraClass($class) {
function removeExtraClass($class) {
$classes = explode(' ', $class);
$this->extraClasses = array_diff($this->extraClasses, $classes);
+ return $this;
}
function debug() {
View
2  forms/FormAction.php
@@ -39,6 +39,7 @@ class FormAction extends FormField {
*/
function setButtonContent($content) {
$this->buttonContent = (string) $content;
+ return $this;
}
@@ -67,6 +68,7 @@ function actionName() {
*/
function setFullAction($fullAction) {
$this->action = $fullAction;
+ return $this;
}
function Field($properties = array()) {
View
17 forms/FormField.php
@@ -200,6 +200,7 @@ function Title() {
function setTitle($val) {
$this->title = $val;
+ return $this;
}
function RightTitle() {
@@ -208,6 +209,7 @@ function RightTitle() {
function setRightTitle($val) {
$this->rightTitle = $val;
+ return $this;
}
function LeftTitle() {
@@ -216,6 +218,7 @@ function LeftTitle() {
function setLeftTitle($val) {
$this->leftTitle = $val;
+ return $this;
}
/**
@@ -226,6 +229,7 @@ function setLeftTitle($val) {
*/
public function setTabIndex($index) {
$this->tabIndex = $index;
+ return $this;
}
/**
@@ -281,6 +285,7 @@ function extraClass() {
*/
function addExtraClass($class) {
$this->extraClasses[$class] = $class;
+ return $this;
}
/**
@@ -290,6 +295,7 @@ function addExtraClass($class) {
*/
function removeExtraClass($class) {
if(isset($this->extraClasses) && array_key_exists($class, $this->extraClasses)) unset($this->extraClasses[$class]);
+ return $this;
}
/**
@@ -305,6 +311,7 @@ function removeExtraClass($class) {
*/
function setAttribute($name, $value) {
$this->attributes[$name] = $value;
+ return $this;
}
/**
@@ -378,6 +385,7 @@ function attrValue() {
*/
function setValue($value) {
$this->value = $value; return $this;
+ return $this;
}
/**
@@ -385,6 +393,7 @@ function setValue($value) {
*/
function setName($name) {
$this->name = $name;
+ return $this;
}
/**
@@ -394,6 +403,7 @@ function setName($name) {
*/
function setForm($form) {
$this->form = $form;
+ return $this;
}
/**
@@ -423,6 +433,7 @@ public function getFieldHolderTemplate() {
*/
public function setFieldHolderTemplate($template) {
$this->fieldHolderTemplate = $template;
+ return $this;
}
/**
@@ -443,6 +454,7 @@ public function securityTokenEnabled() {
function setError($message, $messageType) {
$this->message = $message;
$this->messageType = $messageType;
+ return $this;
}
/**
@@ -454,6 +466,7 @@ function setError($message, $messageType) {
*/
public function setCustomValidationMessage($msg) {
$this->customValidationMessage = $msg;
+ return $this;
}
/**
@@ -477,6 +490,7 @@ public function getCustomValidationMessage() {
*/
function setTemplate($template) {
$this->template = $template;
+ return $this;
}
/**
@@ -569,6 +583,7 @@ function isReadonly() {
*/
function setReadonly($bool) {
$this->readonly = $bool;
+ return $this;
}
/**
@@ -585,6 +600,7 @@ function isDisabled() {
*/
function setDisabled($bool) {
$this->disabled = $bool;
+ return $this;
}
/**
@@ -738,6 +754,7 @@ public function name_to_label($fieldName) {
*/
function setContainerFieldSet($containerFieldSet) {
$this->containerFieldSet = $containerFieldSet;
+ return $this;
}
function rootFieldSet() {
View
7 forms/HtmlEditorConfig.php
@@ -121,7 +121,8 @@ function getOption($k) {
* @return mixed - $v returned for chaining
*/
function setOption($k,$v) {
- return $this->settings[$k] = $v;
+ $this->settings[$k] = $v;
+ return $this;
}
/**
@@ -133,6 +134,7 @@ function setOptions($a) {
foreach ($a as $k=>$v) {
$this->settings[$k] = $v;
}
+ return $this;
}
/**
@@ -173,6 +175,7 @@ function disablePlugins() {
unset($this->plugins[$plugin]);
}
}
+ return $this;
}
/**
@@ -198,6 +201,7 @@ function setButtonsForLine() {
$line = array_shift($buttons);
}
$this->buttons[$line] = is_array($buttons) ? $buttons : array($buttons);
+ return $this;
}
/**
@@ -214,6 +218,7 @@ function addButtonsToLine() {
foreach ($inserts as $button) {
$this->buttons[$line][] = $button;
}
+ return $this;
}
/**
View
5 forms/ListboxField.php
@@ -118,6 +118,7 @@ function getAttributes() {
*/
function setSize($size) {
$this->size = $size;
+ return $this;
}
/**
@@ -126,6 +127,7 @@ function setSize($size) {
*/
function setMultiple($bool) {
$this->multiple = $bool;
+ return $this;
}
function setSource($source) {
@@ -137,6 +139,8 @@ function setSource($source) {
}
parent::setSource($source);
+
+ return $this;
}
/**
@@ -180,6 +184,7 @@ function setValue($val) {
parent::setValue($val);
}
+ return $this;
}
}
View
4 forms/LiteralField.php
@@ -42,6 +42,7 @@ function Field() {
*/
function setContent($content) {
$this->content = $content;
+ return $this;
}
/**
@@ -55,7 +56,8 @@ function getContent() {
* Synonym of {@link setContent()} so that LiteralField is more compatible with other field types.
*/
function setValue($value) {
- return $this->setContent($value);
+ $this->setContent($value);
+ return $this;
}
function performReadonlyTransformation() {
View
9 forms/MoneyField.php
@@ -87,6 +87,8 @@ function setValue($val) {
// decimal and thousands signs, while respecting the stored
// precision in the database without truncating it during display
// and subsequent save operations
+
+ return $this;
}
/**
@@ -129,6 +131,8 @@ function setReadonly($bool) {
$this->fieldAmount->setReadonly($bool);
$this->fieldCurrency->setReadonly($bool);
+
+ return $this;
}
function setDisabled($bool) {
@@ -136,6 +140,8 @@ function setDisabled($bool) {
$this->fieldAmount->setDisabled($bool);
$this->fieldCurrency->setDisabled($bool);
+
+ return $this;
}
/**
@@ -148,6 +154,8 @@ function setAllowedCurrencies($arr) {
$oldVal = $this->fieldCurrency->Value();
$this->fieldCurrency = $this->FieldCurrency($this->name);
$this->fieldCurrency->setValue($oldVal);
+
+ return $this;
}
/**
@@ -159,6 +167,7 @@ function getAllowedCurrencies() {
function setLocale($locale) {
$this->_locale = $locale;
+ return $this;
}
function getLocale() {
View
5 forms/NullableField.php
@@ -61,6 +61,7 @@ function getIsNullLabel() {
*/
function setIsNullLabel(string $isNulLabel){
$this->isNullLabel = $isNulLabel;
+ return $this;
}
/**
@@ -95,6 +96,8 @@ function setValue($value, $data = null) {
}
$this->valueField->setValue($value);
parent::setValue($value);
+
+ return $this;
}
/**
@@ -105,6 +108,8 @@ function setName($name) {
// We need to pass through the name change to the underlying value field.
$this->valueField->setName($name);
parent::setName($name);
+
+ return $this;
}
/**
View
1  forms/OptionsetField.php
@@ -108,6 +108,7 @@ function performReadonlyTransformation() {
*/
function setDisabledItems($items) {
$this->disabledItems = $items;
+ return $this;
}
/**
View
1  forms/Tab.php
@@ -56,6 +56,7 @@ public function Fields() {
public function setTabSet($val) {
$this->tabSet = $val;
+ return $this;
}
/**
View
2  forms/TabSet.php
@@ -95,7 +95,9 @@ public function setTabs($children){
public function setTabSet($val) {
$this->tabSet = $val;
+ return $this;
}
+
public function getTabSet() {
if(isset($this->tabSet)) return $this->tabSet;
}
View
3  forms/TableField.php
@@ -454,6 +454,7 @@ function sortData($data, $recordID = null) {
*/
function setExtraData($extraData) {
$this->extraData = $extraData;
+ return $this;
}
/**
@@ -480,6 +481,7 @@ function FieldHolder() {
function setTransformationConditions($conditions) {
$this->transformationConditions = $conditions;
+ return $this;
}
function jsValidation() {
@@ -580,6 +582,7 @@ function validate($validator) {
function setRequiredFields($fields) {
$this->requiredFields = $fields;
+ return $this;
}
}
View
19 forms/TableListField.php
@@ -385,10 +385,12 @@ function Actions() {
*/
function setCustomQuery(DataList $dataList) {
$this->dataList = $dataList;
+ return $this;
}
function setCustomCsvQuery(DataList $dataList) {
$this->customCsvQuery = $query;
+ return $this;
}
function setCustomSourceItems(SS_List $items) {
@@ -400,6 +402,8 @@ function setCustomSourceItems(SS_List $items) {
} else {
user_error('TableList::setCustomSourceItems() should be passed a SS_List', E_USER_WARNING);
}
+
+ return $this;
}
/**
@@ -499,6 +503,7 @@ function FieldList() {
*/
function setClick_AjaxLoad($urlBase, $formID) {
$this->clickAction = "this.ajaxRequest('" . addslashes($urlBase) . "', '" . addslashes($formID) . "')";
+ return $this;
}
/**
@@ -506,6 +511,7 @@ function setClick_AjaxLoad($urlBase, $formID) {
*/
function setClick_PopupLoad($urlBase) {
$this->clickAction = "var w = window.open(baseHref() + '$urlBase' + this.id.replace(/.*-(\d*)$/,'$1'), 'popup'); w.focus();";
+ return $this;
}
function performReadonlyTransformation() {
@@ -701,6 +707,7 @@ function Can($mode) {
function setPermissions($arr) {
$this->permissions = $arr;
+ return $this;
}
/**
@@ -717,6 +724,7 @@ function getPermissions() {
*/
function setShowPagination($bool) {
$this->showPagination = (bool)$bool;
+ return $this;
}
/**
@@ -731,6 +739,7 @@ function ShowPagination() {
function setPageSize($pageSize) {
$this->pageSize = $pageSize;
+ return $this;
}
function PageSize() {
@@ -748,6 +757,7 @@ function ListStart() {
function setExtraLinkParams($params){
Deprecation::notice('2.4', 'Put the query string onto your FormAction instead().');
$this->extraLinkParams = $params;
+ return $this;
}
/**
@@ -907,6 +917,7 @@ function filterString() {
*/
function setFieldListCsv($fields) {
$this->fieldListCsv = $fields;
+ return $this;
}
/**
@@ -914,6 +925,7 @@ function setFieldListCsv($fields) {
*/
function setCsvSeparator($csvSeparator) {
$this->csvSeparator = $csvSeparator;
+ return $this;
}
/**
@@ -928,6 +940,7 @@ function getCsvSeparator() {
*/
function removeCsvHeader() {
$this->csvHasHeader = false;
+ return $this;
}
/**
@@ -1099,14 +1112,17 @@ function ajax_refresh() {
function setFieldCasting($casting) {
$this->fieldCasting = $casting;
+ return $this;
}
function setFieldFormatting($formatting) {
$this->fieldFormatting = $formatting;
+ return $this;
}
function setCSVFieldFormatting($formatting) {
$this->csvFieldFormatting = $formatting;
+ return $this;
}
/**
@@ -1114,6 +1130,7 @@ function setCSVFieldFormatting($formatting) {
*/
function setFieldList($fieldList) {
$this->fieldList = $fieldList;
+ return $this;
}
/**
@@ -1147,6 +1164,7 @@ function NamePlural() {
function setTemplate($template) {
$this->template = $template;
+ return $this;
}
function CurrentLink() {
@@ -1241,6 +1259,7 @@ function getCastedValue($value, $castingDefinition) {
function setHighlightConditions($conditions) {
$this->highlightConditions = $conditions;
+ return $this;
}
/**
View
1  forms/TextField.php
@@ -27,6 +27,7 @@ function __construct($name, $title = null, $value = '', $maxLength = null, $form
*/
function setMaxLength($length) {
$this->maxLength = $length;
+ return $this;
}
/**
View
2  forms/TextareaField.php
@@ -100,6 +100,7 @@ function Type() {
*/
function setRows($rows) {
$this->rows = $rows;
+ return $this;
}
/**
@@ -109,6 +110,7 @@ function setRows($rows) {
*/
function setColumns($cols) {
$this->cols = $cols;
+ return $this;
}
function Value() {
View
4 forms/TimeField.php
@@ -116,6 +116,8 @@ function setValue($val) {
$this->value = null;
$this->valueObj = null;
}
+
+ return $this;
}
/**
@@ -165,6 +167,7 @@ function getLocale() {
*/
function setLocale($locale) {
$this->locale = $locale;
+ return $this;
}
/**
@@ -173,6 +176,7 @@ function setLocale($locale) {
*/
function setConfig($name, $val) {
$this->config[$name] = $val;
+ return $this;
}
/**
View
4 forms/TreeDropdownField.php
@@ -98,6 +98,7 @@ public function __construct($name, $title = null, $sourceObject = 'Group', $keyF
*/
public function setTreeBaseID($ID) {
$this->baseID = (int) $ID;
+ return $this;
}
/**
@@ -112,6 +113,7 @@ public function setFilterFunction($callback) {
}
$this->filterCallback = $callback;
+ return $this;
}
/**
@@ -126,6 +128,7 @@ public function setSearchFunction($callback) {
}
$this->searchCallback = $callback;
+ return $this;
}
public function getShowSearch() {
@@ -137,6 +140,7 @@ public function getShowSearch() {
*/
public function setShowSearch($bool) {
$this->showSearch = $bool;
+ return $this;
}
/**
View
2  forms/Validator.php
@@ -79,6 +79,7 @@ public function setJavascriptValidationHandler($handler) {
} else {
user_error("Validator::setJavascriptValidationHandler() passed bad handler '$handler'", E_USER_WARNING);
}
+ return $this;
}
/**
@@ -96,6 +97,7 @@ public function getJavascriptValidationHandler() {
*/
function setForm($form) {
$this->form = $form;
+ return $this;
}
/**
Please sign in to comment.
Something went wrong with that request. Please try again.