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',
'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'

View File

@ -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

View File

@ -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()));
}

View File

@ -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);
}

View File

@ -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++;
}

View File

@ -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);
}
}

View File

@ -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";
}
/**

View File

@ -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;
}
}
}

View File

@ -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 . "]";

View File

@ -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,

View File

@ -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() {

View File

@ -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() {

View File

@ -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');
}

View File

@ -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;