MINOR: Removed usage of deprecated FormField::Name()

This commit is contained in:
Sam Minnee 2011-10-29 17:01:52 +13:00
parent da64123116
commit a49b56a348
14 changed files with 55 additions and 51 deletions

View File

@ -25,7 +25,7 @@ class CheckboxField extends FormField {
'type' => 'checkbox', 'type' => 'checkbox',
'class' => ($this->extraClass() ? $this->extraClass() : ''), 'class' => ($this->extraClass() ? $this->extraClass() : ''),
'id' => $this->id(), 'id' => $this->id(),
'name' => $this->Name(), 'name' => $this->getName(),
'value' => 1, 'value' => 1,
'checked' => $this->value ? 'checked' : '', 'checked' => $this->value ? 'checked' : '',
'tabindex' => $this->getTabIndex() 'tabindex' => $this->getTabIndex()
@ -125,7 +125,7 @@ class CheckboxField_Disabled extends CheckboxField {
'type' => 'checkbox', 'type' => 'checkbox',
'class' => ($this->extraClass() ? $this->extraClass() : ''), 'class' => ($this->extraClass() ? $this->extraClass() : ''),
'id' => $this->id(), 'id' => $this->id(),
'name' => $this->Name(), 'name' => $this->getName(),
'tabindex' => $this->getTabIndex(), 'tabindex' => $this->getTabIndex(),
'checked' => ($this->value) ? 'checked' : false, 'checked' => ($this->value) ? 'checked' : false,
'disabled' => 'disabled' 'disabled' => 'disabled'

View File

@ -142,7 +142,7 @@ class CompositeField extends FormField {
$isIncluded = ($field->hasData()); $isIncluded = ($field->hasData());
} }
if($isIncluded) { if($isIncluded) {
$name = $field->Name(); $name = $field->getName();
if($name) { if($name) {
$formName = (isset($this->form)) ? $this->form->FormName() : '(unknown form)'; $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); 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; $i = 0;
foreach($this->children as $child) { foreach($this->children as $child) {
if($child->Name() == $field->Name()) return $i; if($child->getName() == $field->getName()) return $i;
$i++; $i++;
} }
@ -279,7 +279,7 @@ class CompositeField extends FormField {
* @param string|FormField * @param string|FormField
*/ */
function makeFieldReadonly($field) { 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 // Iterate on items, looking for the applicable field
foreach($this->children as $i => $item) { foreach($this->children as $i => $item) {
@ -287,7 +287,7 @@ class CompositeField extends FormField {
$item->makeFieldReadonly($fieldName); $item->makeFieldReadonly($fieldName);
} else { } else {
// Once it's found, use FormField::transform to turn the field into a readonly version of itself. // 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())); $this->children->replaceField($fieldName, $item->transform(new ReadonlyTransformation()));
// Clear an internal cache // Clear an internal cache

View File

@ -187,15 +187,15 @@ class ConfirmedPasswordField extends FormField {
$this->value = $value['_Password']; $this->value = $value['_Password'];
} }
if($this->showOnClick && isset($value['_PasswordFieldVisible'])){ 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 { } else {
if($value || (!$value && $this->canBeEmpty)) { if($value || (!$value && $this->canBeEmpty)) {
$this->value = $value; $this->value = $value;
} }
} }
$this->children->fieldByName($this->Name() . '[_Password]')->setValue($this->value); $this->children->fieldByName($this->getName() . '[_Password]')->setValue($this->value);
$this->children->fieldByName($this->Name() . '[_ConfirmPassword]')->setValue($this->value); $this->children->fieldByName($this->getName() . '[_ConfirmPassword]')->setValue($this->value);
} }
function jsValidation() { function jsValidation() {
@ -297,7 +297,7 @@ JS;
* @return bool * @return bool
*/ */
function isSaveable() { function isSaveable() {
$isVisible = $this->children->fieldByName($this->Name() . '[_PasswordFieldVisible]'); $isVisible = $this->children->fieldByName($this->getName() . '[_PasswordFieldVisible]');
return (!$this->showOnClick || ($this->showOnClick && $isVisible && $isVisible->Value())); return (!$this->showOnClick || ($this->showOnClick && $isVisible && $isVisible->Value()));
} }

View File

@ -59,7 +59,7 @@ class DatetimeField extends FormField {
$this->dateField = Object::create('DateField', $name . '[date]', false); $this->dateField = Object::create('DateField', $name . '[date]', false);
$this->timeField = Object::create('TimeField', $name . '[time]', 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); parent::__construct($name, $title, $value);
} }

View File

@ -67,7 +67,7 @@ class FieldList extends ArrayList {
$isIncluded = ($field->hasData()); $isIncluded = ($field->hasData());
} }
if($isIncluded) { if($isIncluded) {
$name = $field->Name(); $name = $field->getName();
if(isset($list[$name])) { if(isset($list[$name])) {
$errSuffix = ""; $errSuffix = "";
if($this->form) $errSuffix = " in your '{$this->form->class}' form called '" . $this->form->Name() . "'"; 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 // Check if a field by the same name exists in this tab
if($insertBefore) { if($insertBefore) {
$tab->insertBefore($field, $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 // It exists, so we need to replace the old one
$this->replaceField($field->Name(), $field); $this->replaceField($field->getName(), $field);
} else { } else {
$tab->push($field); $tab->push($field);
} }
@ -175,7 +175,7 @@ class FieldList extends ArrayList {
foreach($this->items as $i => $child) { foreach($this->items as $i => $child) {
if(is_object($child)){ if(is_object($child)){
$childName = $child->Name(); $childName = $child->getName();
if(!$childName) $childName = $child->Title(); if(!$childName) $childName = $child->Title();
if(($childName == $fieldName) && (!$dataFieldOnly || $child->hasData())) { if(($childName == $fieldName) && (!$dataFieldOnly || $child->hasData())) {
@ -200,7 +200,7 @@ class FieldList extends ArrayList {
$this->flushFieldsCache(); $this->flushFieldsCache();
foreach($this->items as $i => $field) { foreach($this->items as $i => $field) {
if(is_object($field)) { if(is_object($field)) {
if($field->Name() == $fieldName && $field->hasData()) { if($field->getName() == $fieldName && $field->hasData()) {
$this->items[$i] = $newField; $this->items[$i] = $newField;
return true; return true;
@ -273,7 +273,7 @@ class FieldList extends ArrayList {
} }
$parentPointer->push($currentPointer); $parentPointer->push($currentPointer);
} else { } 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); 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; else $remainder = null;
foreach($this->items as $child) { 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($remainder) {
if($child->isComposite()) { if($child->isComposite()) {
return $child->fieldByName($remainder); return $child->fieldByName($remainder);
@ -318,7 +318,7 @@ class FieldList extends ArrayList {
public function dataFieldByName($name) { public function dataFieldByName($name) {
if($dataFields = $this->dataFields()) { if($dataFields = $this->dataFields()) {
foreach($dataFields as $child) { 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; $i = 0;
foreach($this->items as $child) { 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)); array_splice($this->items, $i, 0, array($item));
return $item; return $item;
} elseif($child->isComposite()) { } elseif($child->isComposite()) {
@ -360,7 +360,7 @@ class FieldList extends ArrayList {
$i = 0; $i = 0;
foreach($this->items as $child) { 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)); array_splice($this->items, $i+1, 0, array($item));
return $item; return $item;
} elseif($child->isComposite()) { } elseif($child->isComposite()) {
@ -390,7 +390,7 @@ class FieldList extends ArrayList {
*/ */
protected function onBeforeInsert($item) { protected function onBeforeInsert($item) {
$this->flushFieldsCache(); $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) { public function setValues($data) {
foreach($this->dataFields() as $field) { foreach($this->dataFields() as $field) {
$fieldName = $field->Name(); $fieldName = $field->getName();
if(isset($data[$fieldName])) $field->setValue($data[$fieldName]); if(isset($data[$fieldName])) $field->setValue($data[$fieldName]);
} }
} }
@ -475,7 +475,7 @@ class FieldList extends ArrayList {
* @param string|FormField * @param string|FormField
*/ */
function makeFieldReadonly($field) { function makeFieldReadonly($field) {
$fieldName = ($field instanceof FormField) ? $field->Name() : $field; $fieldName = ($field instanceof FormField) ? $field->getName() : $field;
$srcField = $this->dataFieldByName($fieldName); $srcField = $this->dataFieldByName($fieldName);
$this->replaceField($fieldName, $srcField->performReadonlyTransformation()); $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. // Build a map of fields indexed by their name. This will make the 2nd step much easier.
$fieldMap = array(); $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. // 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. // 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. * @return Position in children collection (first position starts with 0). Returns FALSE if the field can't be found.
*/ */
function fieldPosition($field) { function fieldPosition($field) {
if(is_object($field)) $field = $field->Name(); if(is_object($field)) $field = $field->getName();
$i = 0; $i = 0;
foreach($this->dataFields() as $child) { foreach($this->dataFields() as $child) {
if($child->Name() == $field) return $i; if($child->getName() == $field) return $i;
$i++; $i++;
} }

View File

@ -487,7 +487,7 @@ class Form extends RequestHandler {
*/ */
function Fields() { function Fields() {
foreach($this->getExtraFields() as $field) { 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; return $this->fields;
@ -522,7 +522,7 @@ class Form extends RequestHandler {
*/ */
function dataFieldByName($name) { function dataFieldByName($name) {
foreach($this->getExtraFields() as $field) { 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); return $this->fields->dataFieldByName($name);
@ -567,7 +567,7 @@ class Form extends RequestHandler {
*/ */
function unsetDataFieldByName($fieldName){ function unsetDataFieldByName($fieldName){
foreach($this->Fields()->dataFields() as $child) { 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; $child = null;
} }
} }
@ -948,7 +948,7 @@ class Form extends RequestHandler {
// dont include fields without data // dont include fields without data
$dataFields = $this->fields->dataFields(); $dataFields = $this->fields->dataFields();
if($dataFields) foreach($dataFields as $field) { if($dataFields) foreach($dataFields as $field) {
$name = $field->Name(); $name = $field->getName();
// Skip fields that have been exlcuded // Skip fields that have been exlcuded
if($fieldList && !in_array($name, $fieldList)) continue; if($fieldList && !in_array($name, $fieldList)) continue;
@ -1004,16 +1004,16 @@ class Form extends RequestHandler {
$lastField = null; $lastField = null;
if($dataFields) foreach($dataFields as $field) { if($dataFields) foreach($dataFields as $field) {
// Skip fields that have been exlcuded // 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; $lastField = $field;
}else if( $dataObject->hasMethod( $saveMethod ) ){ }else if( $dataObject->hasMethod( $saveMethod ) ){
$dataObject->$saveMethod( $field->dataValue()); $dataObject->$saveMethod( $field->dataValue());
} else if($field->Name() != "ID"){ } else if($field->getName() != "ID"){
$field->saveInto($dataObject); $field->saveInto($dataObject);
} }
} }
@ -1036,8 +1036,8 @@ class Form extends RequestHandler {
if($dataFields){ if($dataFields){
foreach($dataFields as $field) { foreach($dataFields as $field) {
if($field->Name()) { if($field->getName()) {
$data[$field->Name()] = $field->dataValue(); $data[$field->getName()] = $field->dataValue();
} }
} }
} }
@ -1054,7 +1054,7 @@ class Form extends RequestHandler {
function resetField($fieldName, $fieldValue = null) { function resetField($fieldName, $fieldValue = null) {
$dataFields = $this->fields->dataFields(); $dataFields = $this->fields->dataFields();
if($dataFields) foreach($dataFields as $field) { if($dataFields) foreach($dataFields as $field) {
if($field->Name()==$fieldName) { if($field->getName()==$fieldName) {
$field = $field->setValue($fieldValue); $field = $field->setValue($fieldValue);
} }
} }

View File

@ -44,7 +44,7 @@ class NullableField extends FormField {
// Set a default label if one is not provided. // Set a default label if one is not provided.
$this->isNullLabel = _t('NullableField.IsNullLabel', 'Is Null', PR_HIGH); $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(); $this->readonly = $valueField->isReadonly();
} }
@ -68,7 +68,7 @@ class NullableField extends FormField {
* @return string * @return string
*/ */
function getIsNullId() { function getIsNullId() {
return $this->Name() . "_IsNull"; return $this->getName() . "_IsNull";
} }
/** /**

View File

@ -63,7 +63,7 @@ class Tab extends CompositeField {
*/ */
public function fieldByName($name) { public function fieldByName($name) {
foreach($this->children as $child) { foreach($this->children as $child) {
if($name == $child->Name()) return $child; if($name == $child->getName()) return $child;
} }
} }
} }

View File

@ -635,7 +635,7 @@ class TableField_Item extends TableListField_Item {
if($this->fieldset) { if($this->fieldset) {
$i=0; $i=0;
foreach($this->fieldset as $field) { foreach($this->fieldset as $field) {
$origFieldName = $field->Name(); $origFieldName = $field->getName();
// set unique fieldname with id // set unique fieldname with id
$combinedFieldName = $this->parent->Name() . "[" . $this->ID() . "][" . $origFieldName . "]"; $combinedFieldName = $this->parent->Name() . "[" . $this->ID() . "][" . $origFieldName . "]";

View File

@ -39,7 +39,7 @@ class TextField extends FormField {
'type' => 'text', 'type' => 'text',
'class' => 'text' . ($this->extraClass() ? $this->extraClass() : ''), 'class' => 'text' . ($this->extraClass() ? $this->extraClass() : ''),
'id' => $this->id(), 'id' => $this->id(),
'name' => $this->Name(), 'name' => $this->getName(),
'value' => $this->Value(), 'value' => $this->Value(),
'tabindex' => $this->getTabIndex(), 'tabindex' => $this->getTabIndex(),
'maxlength' => ($this->maxLength) ? $this->maxLength : null, 'maxlength' => ($this->maxLength) ? $this->maxLength : null,

View File

@ -7,12 +7,12 @@ class ConfirmedPasswordFieldTest extends SapphireTest {
function testSetValue() { function testSetValue() {
$field = new ConfirmedPasswordField('Test', 'Testing', 'valueA'); $field = new ConfirmedPasswordField('Test', 'Testing', 'valueA');
$this->assertEquals('valueA', $field->Value()); $this->assertEquals('valueA', $field->Value());
$this->assertEquals('valueA', $field->children->fieldByName($field->Name() . '[_Password]')->Value()); $this->assertEquals('valueA', $field->children->fieldByName($field->getName() . '[_Password]')->Value());
$this->assertEquals('valueA', $field->children->fieldByName($field->Name() . '[_ConfirmPassword]')->Value()); $this->assertEquals('valueA', $field->children->fieldByName($field->getName() . '[_ConfirmPassword]')->Value());
$field->setValue('valueB'); $field->setValue('valueB');
$this->assertEquals('valueB', $field->Value()); $this->assertEquals('valueB', $field->Value());
$this->assertEquals('valueB', $field->children->fieldByName($field->Name() . '[_Password]')->Value()); $this->assertEquals('valueB', $field->children->fieldByName($field->getName() . '[_Password]')->Value());
$this->assertEquals('valueB', $field->children->fieldByName($field->Name() . '[_ConfirmPassword]')->Value()); $this->assertEquals('valueB', $field->children->fieldByName($field->getName() . '[_ConfirmPassword]')->Value());
} }
function testSetShowOnClick() { function testSetShowOnClick() {

View File

@ -333,7 +333,7 @@ class FieldListTest extends SapphireTest {
$this->assertEquals(4, $fields->Count()); $this->assertEquals(4, $fields->Count());
/* The position of the Title field is at number 3 */ /* The position of the Title field is at number 3 */
$this->assertEquals('Title', $fields[2]->Name()); $this->assertEquals('Title', $fields[2]->getName());
} }
function testInsertBeforeMultipleFields() { function testInsertBeforeMultipleFields() {
@ -383,7 +383,7 @@ class FieldListTest extends SapphireTest {
$this->assertEquals(4, $fields->Count()); $this->assertEquals(4, $fields->Count());
/* The position of the Title field should be at number 2 */ /* 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() { function testrootFieldSet() {

View File

@ -112,7 +112,7 @@ class SecurityTokenTest extends SapphireTest {
$f = $fs->dataFieldByName($t->getName()); $f = $fs->dataFieldByName($t->getName());
$this->assertType('HiddenField', $f); $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'); $this->assertEquals($f->Value(), $t->getValue(), 'Value matches');
} }

View File

@ -364,7 +364,11 @@ class ViewableData extends Object implements IteratorAggregate {
if(!$cacheName) $cacheName = $arguments ? $fieldName . implode(',', $arguments) : $fieldName; if(!$cacheName) $cacheName = $arguments ? $fieldName . implode(',', $arguments) : $fieldName;
if(!isset($this->objCache[$cacheName])) { 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(); $value = $arguments ? call_user_func_array(array($this, $fieldName), $arguments) : $this->$fieldName();
} else { } else {
$value = $this->$fieldName; $value = $this->$fieldName;