From a49b56a348ff7d176704b6f9ac09175981ed2c86 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Sat, 29 Oct 2011 17:01:52 +1300 Subject: [PATCH] MINOR: Removed usage of deprecated FormField::Name() --- forms/CheckboxField.php | 4 +-- forms/CompositeField.php | 8 +++--- forms/ConfirmedPasswordField.php | 8 +++--- forms/DatetimeField.php | 2 +- forms/FieldList.php | 32 +++++++++++----------- forms/Form.php | 22 +++++++-------- forms/NullableField.php | 4 +-- forms/Tab.php | 2 +- forms/TableField.php | 2 +- forms/TextField.php | 2 +- tests/forms/ConfirmedPasswordFieldTest.php | 8 +++--- tests/forms/FieldListTest.php | 4 +-- tests/security/SecurityTokenTest.php | 2 +- view/ViewableData.php | 6 +++- 14 files changed, 55 insertions(+), 51 deletions(-) diff --git a/forms/CheckboxField.php b/forms/CheckboxField.php index 37890535d..5bb562e81 100644 --- a/forms/CheckboxField.php +++ b/forms/CheckboxField.php @@ -25,7 +25,7 @@ class CheckboxField extends FormField { 'type' => 'checkbox', 'class' => ($this->extraClass() ? $this->extraClass() : ''), 'id' => $this->id(), - 'name' => $this->Name(), + 'name' => $this->getName(), 'value' => 1, 'checked' => $this->value ? 'checked' : '', 'tabindex' => $this->getTabIndex() @@ -125,7 +125,7 @@ class CheckboxField_Disabled extends CheckboxField { 'type' => 'checkbox', 'class' => ($this->extraClass() ? $this->extraClass() : ''), 'id' => $this->id(), - 'name' => $this->Name(), + 'name' => $this->getName(), 'tabindex' => $this->getTabIndex(), 'checked' => ($this->value) ? 'checked' : false, 'disabled' => 'disabled' diff --git a/forms/CompositeField.php b/forms/CompositeField.php index 7ca6aabc6..03f2054ca 100644 --- a/forms/CompositeField.php +++ b/forms/CompositeField.php @@ -142,7 +142,7 @@ class CompositeField extends FormField { $isIncluded = ($field->hasData()); } if($isIncluded) { - $name = $field->Name(); + $name = $field->getName(); if($name) { $formName = (isset($this->form)) ? $this->form->FormName() : '(unknown form)'; if(isset($list[$name])) user_error("collateDataFields() I noticed that a field called '$name' appears twice in your form: '{$formName}'. One is a '{$field->class}' and the other is a '{$list[$name]->class}'", E_USER_ERROR); @@ -266,7 +266,7 @@ class CompositeField extends FormField { $i = 0; foreach($this->children as $child) { - if($child->Name() == $field->Name()) return $i; + if($child->getName() == $field->getName()) return $i; $i++; } @@ -279,7 +279,7 @@ class CompositeField extends FormField { * @param string|FormField */ function makeFieldReadonly($field) { - $fieldName = ($field instanceof FormField) ? $field->Name() : $field; + $fieldName = ($field instanceof FormField) ? $field->getName() : $field; // Iterate on items, looking for the applicable field foreach($this->children as $i => $item) { @@ -287,7 +287,7 @@ class CompositeField extends FormField { $item->makeFieldReadonly($fieldName); } else { // Once it's found, use FormField::transform to turn the field into a readonly version of itself. - if($item->Name() == $fieldName) { + if($item->getName() == $fieldName) { $this->children->replaceField($fieldName, $item->transform(new ReadonlyTransformation())); // Clear an internal cache diff --git a/forms/ConfirmedPasswordField.php b/forms/ConfirmedPasswordField.php index 4f3373252..06684f53f 100644 --- a/forms/ConfirmedPasswordField.php +++ b/forms/ConfirmedPasswordField.php @@ -187,15 +187,15 @@ class ConfirmedPasswordField extends FormField { $this->value = $value['_Password']; } if($this->showOnClick && isset($value['_PasswordFieldVisible'])){ - $this->children->fieldByName($this->Name() . '[_PasswordFieldVisible]')->setValue($value['_PasswordFieldVisible']); + $this->children->fieldByName($this->getName() . '[_PasswordFieldVisible]')->setValue($value['_PasswordFieldVisible']); } } else { if($value || (!$value && $this->canBeEmpty)) { $this->value = $value; } } - $this->children->fieldByName($this->Name() . '[_Password]')->setValue($this->value); - $this->children->fieldByName($this->Name() . '[_ConfirmPassword]')->setValue($this->value); + $this->children->fieldByName($this->getName() . '[_Password]')->setValue($this->value); + $this->children->fieldByName($this->getName() . '[_ConfirmPassword]')->setValue($this->value); } function jsValidation() { @@ -297,7 +297,7 @@ JS; * @return bool */ function isSaveable() { - $isVisible = $this->children->fieldByName($this->Name() . '[_PasswordFieldVisible]'); + $isVisible = $this->children->fieldByName($this->getName() . '[_PasswordFieldVisible]'); return (!$this->showOnClick || ($this->showOnClick && $isVisible && $isVisible->Value())); } diff --git a/forms/DatetimeField.php b/forms/DatetimeField.php index 6d2f53853..72720e424 100644 --- a/forms/DatetimeField.php +++ b/forms/DatetimeField.php @@ -59,7 +59,7 @@ class DatetimeField extends FormField { $this->dateField = Object::create('DateField', $name . '[date]', false); $this->timeField = Object::create('TimeField', $name . '[time]', false); - $this->timezoneField = new HiddenField($this->Name() . '[timezone]'); + $this->timezoneField = new HiddenField($this->getName() . '[timezone]'); parent::__construct($name, $title, $value); } diff --git a/forms/FieldList.php b/forms/FieldList.php index 1c93b9609..9c3ee81f0 100644 --- a/forms/FieldList.php +++ b/forms/FieldList.php @@ -67,7 +67,7 @@ class FieldList extends ArrayList { $isIncluded = ($field->hasData()); } if($isIncluded) { - $name = $field->Name(); + $name = $field->getName(); if(isset($list[$name])) { $errSuffix = ""; if($this->form) $errSuffix = " in your '{$this->form->class}' form called '" . $this->form->Name() . "'"; @@ -119,9 +119,9 @@ class FieldList extends ArrayList { // Check if a field by the same name exists in this tab if($insertBefore) { $tab->insertBefore($field, $insertBefore); - } elseif($tab->fieldByName($field->Name())) { + } elseif($tab->fieldByName($field->getName())) { // It exists, so we need to replace the old one - $this->replaceField($field->Name(), $field); + $this->replaceField($field->getName(), $field); } else { $tab->push($field); } @@ -175,7 +175,7 @@ class FieldList extends ArrayList { foreach($this->items as $i => $child) { if(is_object($child)){ - $childName = $child->Name(); + $childName = $child->getName(); if(!$childName) $childName = $child->Title(); if(($childName == $fieldName) && (!$dataFieldOnly || $child->hasData())) { @@ -200,7 +200,7 @@ class FieldList extends ArrayList { $this->flushFieldsCache(); foreach($this->items as $i => $field) { if(is_object($field)) { - if($field->Name() == $fieldName && $field->hasData()) { + if($field->getName() == $fieldName && $field->hasData()) { $this->items[$i] = $newField; return true; @@ -273,7 +273,7 @@ class FieldList extends ArrayList { } $parentPointer->push($currentPointer); } else { - $withName = ($parentPointer->hasMethod('Name')) ? " named '{$parentPointer->Name()}'" : null; + $withName = ($parentPointer->hasMethod('Name')) ? " named '{$parentPointer->getName()}'" : null; user_error("FieldList::addFieldToTab() Tried to add a tab to object '{$parentPointer->class}'{$withName} - '$part' didn't exist.", E_USER_ERROR); } } @@ -293,7 +293,7 @@ class FieldList extends ArrayList { else $remainder = null; foreach($this->items as $child) { - if(trim($name) == trim($child->Name()) || $name == $child->id) { + if(trim($name) == trim($child->getName()) || $name == $child->id) { if($remainder) { if($child->isComposite()) { return $child->fieldByName($remainder); @@ -318,7 +318,7 @@ class FieldList extends ArrayList { public function dataFieldByName($name) { if($dataFields = $this->dataFields()) { foreach($dataFields as $child) { - if(trim($name) == trim($child->Name()) || $name == $child->id) return $child; + if(trim($name) == trim($child->getName()) || $name == $child->id) return $child; } } } @@ -335,7 +335,7 @@ class FieldList extends ArrayList { $i = 0; foreach($this->items as $child) { - if($name == $child->Name() || $name == $child->id) { + if($name == $child->getName() || $name == $child->id) { array_splice($this->items, $i, 0, array($item)); return $item; } elseif($child->isComposite()) { @@ -360,7 +360,7 @@ class FieldList extends ArrayList { $i = 0; foreach($this->items as $child) { - if($name == $child->Name() || $name == $child->id) { + if($name == $child->getName() || $name == $child->id) { array_splice($this->items, $i+1, 0, array($item)); return $item; } elseif($child->isComposite()) { @@ -390,7 +390,7 @@ class FieldList extends ArrayList { */ protected function onBeforeInsert($item) { $this->flushFieldsCache(); - if($item->Name()) $this->rootFieldSet()->removeByName($item->Name(), true); + if($item->getName()) $this->rootFieldSet()->removeByName($item->getName(), true); } @@ -410,7 +410,7 @@ class FieldList extends ArrayList { */ public function setValues($data) { foreach($this->dataFields() as $field) { - $fieldName = $field->Name(); + $fieldName = $field->getName(); if(isset($data[$fieldName])) $field->setValue($data[$fieldName]); } } @@ -475,7 +475,7 @@ class FieldList extends ArrayList { * @param string|FormField */ function makeFieldReadonly($field) { - $fieldName = ($field instanceof FormField) ? $field->Name() : $field; + $fieldName = ($field instanceof FormField) ? $field->getName() : $field; $srcField = $this->dataFieldByName($fieldName); $this->replaceField($fieldName, $srcField->performReadonlyTransformation()); } @@ -495,7 +495,7 @@ class FieldList extends ArrayList { // Build a map of fields indexed by their name. This will make the 2nd step much easier. $fieldMap = array(); - foreach($this->dataFields() as $field) $fieldMap[$field->Name()] = $field; + foreach($this->dataFields() as $field) $fieldMap[$field->getName()] = $field; // Iterate through the ordered list of names, building a new array to be put into $this->items. // While we're doing this, empty out $fieldMap so that we can keep track of leftovers. @@ -525,11 +525,11 @@ class FieldList extends ArrayList { * @return Position in children collection (first position starts with 0). Returns FALSE if the field can't be found. */ function fieldPosition($field) { - if(is_object($field)) $field = $field->Name(); + if(is_object($field)) $field = $field->getName(); $i = 0; foreach($this->dataFields() as $child) { - if($child->Name() == $field) return $i; + if($child->getName() == $field) return $i; $i++; } diff --git a/forms/Form.php b/forms/Form.php index b58e7bd26..8c9644d08 100644 --- a/forms/Form.php +++ b/forms/Form.php @@ -487,7 +487,7 @@ class Form extends RequestHandler { */ function Fields() { foreach($this->getExtraFields() as $field) { - if(!$this->fields->fieldByName($field->Name())) $this->fields->push($field); + if(!$this->fields->fieldByName($field->getName())) $this->fields->push($field); } return $this->fields; @@ -522,7 +522,7 @@ class Form extends RequestHandler { */ function dataFieldByName($name) { foreach($this->getExtraFields() as $field) { - if(!$this->fields->dataFieldByName($field->Name())) $this->fields->push($field); + if(!$this->fields->dataFieldByName($field->getName())) $this->fields->push($field); } return $this->fields->dataFieldByName($name); @@ -567,7 +567,7 @@ class Form extends RequestHandler { */ function unsetDataFieldByName($fieldName){ foreach($this->Fields()->dataFields() as $child) { - if(is_object($child) && ($child->Name() == $fieldName || $child->Title() == $fieldName)) { + if(is_object($child) && ($child->getName() == $fieldName || $child->Title() == $fieldName)) { $child = null; } } @@ -948,7 +948,7 @@ class Form extends RequestHandler { // dont include fields without data $dataFields = $this->fields->dataFields(); if($dataFields) foreach($dataFields as $field) { - $name = $field->Name(); + $name = $field->getName(); // Skip fields that have been exlcuded if($fieldList && !in_array($name, $fieldList)) continue; @@ -1004,16 +1004,16 @@ class Form extends RequestHandler { $lastField = null; if($dataFields) foreach($dataFields as $field) { // Skip fields that have been exlcuded - if($fieldList && is_array($fieldList) && !in_array($field->Name(), $fieldList)) continue; + if($fieldList && is_array($fieldList) && !in_array($field->getName(), $fieldList)) continue; - $saveMethod = "save{$field->Name()}"; + $saveMethod = "save{$field->getName()}"; - if($field->Name() == "ClassName"){ + if($field->getName() == "ClassName"){ $lastField = $field; }else if( $dataObject->hasMethod( $saveMethod ) ){ $dataObject->$saveMethod( $field->dataValue()); - } else if($field->Name() != "ID"){ + } else if($field->getName() != "ID"){ $field->saveInto($dataObject); } } @@ -1036,8 +1036,8 @@ class Form extends RequestHandler { if($dataFields){ foreach($dataFields as $field) { - if($field->Name()) { - $data[$field->Name()] = $field->dataValue(); + if($field->getName()) { + $data[$field->getName()] = $field->dataValue(); } } } @@ -1054,7 +1054,7 @@ class Form extends RequestHandler { function resetField($fieldName, $fieldValue = null) { $dataFields = $this->fields->dataFields(); if($dataFields) foreach($dataFields as $field) { - if($field->Name()==$fieldName) { + if($field->getName()==$fieldName) { $field = $field->setValue($fieldValue); } } diff --git a/forms/NullableField.php b/forms/NullableField.php index debe517cb..04e15397d 100644 --- a/forms/NullableField.php +++ b/forms/NullableField.php @@ -44,7 +44,7 @@ class NullableField extends FormField { // Set a default label if one is not provided. $this->isNullLabel = _t('NullableField.IsNullLabel', 'Is Null', PR_HIGH); } - parent::__construct($valueField->Name(), $valueField->Title(), $valueField->Value(), $valueField->getForm(), $valueField->RightTitle()); + parent::__construct($valueField->getName(), $valueField->Title(), $valueField->Value(), $valueField->getForm(), $valueField->RightTitle()); $this->readonly = $valueField->isReadonly(); } @@ -68,7 +68,7 @@ class NullableField extends FormField { * @return string */ function getIsNullId() { - return $this->Name() . "_IsNull"; + return $this->getName() . "_IsNull"; } /** diff --git a/forms/Tab.php b/forms/Tab.php index 4fe5e520d..8bf39fc7d 100644 --- a/forms/Tab.php +++ b/forms/Tab.php @@ -63,7 +63,7 @@ class Tab extends CompositeField { */ public function fieldByName($name) { foreach($this->children as $child) { - if($name == $child->Name()) return $child; + if($name == $child->getName()) return $child; } } } diff --git a/forms/TableField.php b/forms/TableField.php index 3480e8b56..056c11417 100644 --- a/forms/TableField.php +++ b/forms/TableField.php @@ -635,7 +635,7 @@ class TableField_Item extends TableListField_Item { if($this->fieldset) { $i=0; foreach($this->fieldset as $field) { - $origFieldName = $field->Name(); + $origFieldName = $field->getName(); // set unique fieldname with id $combinedFieldName = $this->parent->Name() . "[" . $this->ID() . "][" . $origFieldName . "]"; diff --git a/forms/TextField.php b/forms/TextField.php index 62eb48067..fa06f6459 100644 --- a/forms/TextField.php +++ b/forms/TextField.php @@ -39,7 +39,7 @@ class TextField extends FormField { 'type' => 'text', 'class' => 'text' . ($this->extraClass() ? $this->extraClass() : ''), 'id' => $this->id(), - 'name' => $this->Name(), + 'name' => $this->getName(), 'value' => $this->Value(), 'tabindex' => $this->getTabIndex(), 'maxlength' => ($this->maxLength) ? $this->maxLength : null, diff --git a/tests/forms/ConfirmedPasswordFieldTest.php b/tests/forms/ConfirmedPasswordFieldTest.php index 9887eb618..48c30bf97 100644 --- a/tests/forms/ConfirmedPasswordFieldTest.php +++ b/tests/forms/ConfirmedPasswordFieldTest.php @@ -7,12 +7,12 @@ class ConfirmedPasswordFieldTest extends SapphireTest { function testSetValue() { $field = new ConfirmedPasswordField('Test', 'Testing', 'valueA'); $this->assertEquals('valueA', $field->Value()); - $this->assertEquals('valueA', $field->children->fieldByName($field->Name() . '[_Password]')->Value()); - $this->assertEquals('valueA', $field->children->fieldByName($field->Name() . '[_ConfirmPassword]')->Value()); + $this->assertEquals('valueA', $field->children->fieldByName($field->getName() . '[_Password]')->Value()); + $this->assertEquals('valueA', $field->children->fieldByName($field->getName() . '[_ConfirmPassword]')->Value()); $field->setValue('valueB'); $this->assertEquals('valueB', $field->Value()); - $this->assertEquals('valueB', $field->children->fieldByName($field->Name() . '[_Password]')->Value()); - $this->assertEquals('valueB', $field->children->fieldByName($field->Name() . '[_ConfirmPassword]')->Value()); + $this->assertEquals('valueB', $field->children->fieldByName($field->getName() . '[_Password]')->Value()); + $this->assertEquals('valueB', $field->children->fieldByName($field->getName() . '[_ConfirmPassword]')->Value()); } function testSetShowOnClick() { diff --git a/tests/forms/FieldListTest.php b/tests/forms/FieldListTest.php index 7191a67c2..497e6f48a 100644 --- a/tests/forms/FieldListTest.php +++ b/tests/forms/FieldListTest.php @@ -333,7 +333,7 @@ class FieldListTest extends SapphireTest { $this->assertEquals(4, $fields->Count()); /* The position of the Title field is at number 3 */ - $this->assertEquals('Title', $fields[2]->Name()); + $this->assertEquals('Title', $fields[2]->getName()); } function testInsertBeforeMultipleFields() { @@ -383,7 +383,7 @@ class FieldListTest extends SapphireTest { $this->assertEquals(4, $fields->Count()); /* The position of the Title field should be at number 2 */ - $this->assertEquals('Title', $fields[1]->Name()); + $this->assertEquals('Title', $fields[1]->getName()); } function testrootFieldSet() { diff --git a/tests/security/SecurityTokenTest.php b/tests/security/SecurityTokenTest.php index e1c111eff..9826eb4c4 100644 --- a/tests/security/SecurityTokenTest.php +++ b/tests/security/SecurityTokenTest.php @@ -112,7 +112,7 @@ class SecurityTokenTest extends SapphireTest { $f = $fs->dataFieldByName($t->getName()); $this->assertType('HiddenField', $f); - $this->assertEquals($f->Name(), $t->getName(), 'Name matches'); + $this->assertEquals($f->getName(), $t->getName(), 'Name matches'); $this->assertEquals($f->Value(), $t->getValue(), 'Value matches'); } diff --git a/view/ViewableData.php b/view/ViewableData.php index 1a30a643e..1e357ba2c 100644 --- a/view/ViewableData.php +++ b/view/ViewableData.php @@ -364,7 +364,11 @@ class ViewableData extends Object implements IteratorAggregate { if(!$cacheName) $cacheName = $arguments ? $fieldName . implode(',', $arguments) : $fieldName; if(!isset($this->objCache[$cacheName])) { - if($this->hasMethod($fieldName)) { + // HACK: Don't call the deprecated FormField::Name() method + $methodIsAllowed = true; + if($this instanceof FormField && $fieldName == 'Name') $methodIsAllowed = false; + + if($methodIsAllowed && $this->hasMethod($fieldName)) { $value = $arguments ? call_user_func_array(array($this, $fieldName), $arguments) : $this->$fieldName(); } else { $value = $this->$fieldName;