mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
API CHANGE Deprecated FieldSet-specific methods from Form, namely dateFieldByName(), unsetDataFieldByName(), unsetFieldFromTab(), resetField()
This commit is contained in:
parent
7d46e7e751
commit
b3c08dba12
@ -309,7 +309,7 @@ JS;
|
|||||||
}
|
}
|
||||||
|
|
||||||
function sourceID() {
|
function sourceID() {
|
||||||
$idField = $this->form->dataFieldByName('ID');
|
$idField = $this->form->Fields()->dataFieldByName('ID');
|
||||||
|
|
||||||
// disabled as it conflicts with scaffolded formfields, and not strictly necessary
|
// disabled as it conflicts with scaffolded formfields, and not strictly necessary
|
||||||
// if(!$idField) user_error("ComplexTableField needs a formfield named 'ID' to be present", E_USER_ERROR);
|
// if(!$idField) user_error("ComplexTableField needs a formfield named 'ID' to be present", E_USER_ERROR);
|
||||||
|
@ -355,7 +355,7 @@ class Form extends RequestHandler {
|
|||||||
* @return FormField
|
* @return FormField
|
||||||
*/
|
*/
|
||||||
function handleField($request) {
|
function handleField($request) {
|
||||||
$field = $this->dataFieldByName($request->param('FieldName'));
|
$field = $this->Fields()->dataFieldByName($request->param('FieldName'));
|
||||||
|
|
||||||
if($field) {
|
if($field) {
|
||||||
return $field;
|
return $field;
|
||||||
@ -526,9 +526,12 @@ class Form extends RequestHandler {
|
|||||||
* It will traverse into composite fields for you, to find the field you want.
|
* It will traverse into composite fields for you, to find the field you want.
|
||||||
* It will only return a data field.
|
* It will only return a data field.
|
||||||
*
|
*
|
||||||
|
* @deprecated 3.0 Use Fields() and FieldList API instead
|
||||||
* @return FormField
|
* @return FormField
|
||||||
*/
|
*/
|
||||||
function dataFieldByName($name) {
|
function dataFieldByName($name) {
|
||||||
|
Deprecation::notice('3.0', 'Use Fields() and FieldList API instead');
|
||||||
|
|
||||||
foreach($this->getExtraFields() as $field) {
|
foreach($this->getExtraFields() as $field) {
|
||||||
if(!$this->fields->dataFieldByName($field->getName())) $this->fields->push($field);
|
if(!$this->fields->dataFieldByName($field->getName())) $this->fields->push($field);
|
||||||
}
|
}
|
||||||
@ -564,16 +567,23 @@ class Form extends RequestHandler {
|
|||||||
/**
|
/**
|
||||||
* Unset the form's action button by its name.
|
* Unset the form's action button by its name.
|
||||||
*
|
*
|
||||||
|
* @deprecated 3.0 Use Actions() and FieldList API instead
|
||||||
* @param string $name
|
* @param string $name
|
||||||
*/
|
*/
|
||||||
function unsetActionByName($name) {
|
function unsetActionByName($name) {
|
||||||
|
Deprecation::notice('3.0', 'Use Actions() and FieldList API instead');
|
||||||
|
|
||||||
$this->actions->removeByName($name);
|
$this->actions->removeByName($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unset the form's dataField by its name
|
* Unset the form's dataField by its name
|
||||||
|
*
|
||||||
|
* @deprecated 3.0 Use Fields() and FieldList API instead
|
||||||
*/
|
*/
|
||||||
function unsetDataFieldByName($fieldName){
|
function unsetDataFieldByName($fieldName){
|
||||||
|
Deprecation::notice('3.0', 'Use Fields() and FieldList API instead');
|
||||||
|
|
||||||
foreach($this->Fields()->dataFields() as $child) {
|
foreach($this->Fields()->dataFields() as $child) {
|
||||||
if(is_object($child) && ($child->getName() == $fieldName || $child->Title() == $fieldName)) {
|
if(is_object($child) && ($child->getName() == $fieldName || $child->Title() == $fieldName)) {
|
||||||
$child = null;
|
$child = null;
|
||||||
@ -1079,10 +1089,13 @@ class Form extends RequestHandler {
|
|||||||
* Resets a specific field to its passed default value.
|
* Resets a specific field to its passed default value.
|
||||||
* Does NOT clear out all submitted data in the form.
|
* Does NOT clear out all submitted data in the form.
|
||||||
*
|
*
|
||||||
|
* @deprecated 3.0 Use Fields() and FieldList API instead
|
||||||
* @param string $fieldName
|
* @param string $fieldName
|
||||||
* @param mixed $fieldValue
|
* @param mixed $fieldValue
|
||||||
*/
|
*/
|
||||||
function resetField($fieldName, $fieldValue = null) {
|
function resetField($fieldName, $fieldValue = null) {
|
||||||
|
Deprecation::notice('3.0', 'Use Fields() and FieldList API instead');
|
||||||
|
|
||||||
$dataFields = $this->fields->dataFields();
|
$dataFields = $this->fields->dataFields();
|
||||||
if($dataFields) foreach($dataFields as $field) {
|
if($dataFields) foreach($dataFields as $field) {
|
||||||
if($field->getName()==$fieldName) {
|
if($field->getName()==$fieldName) {
|
||||||
|
@ -46,7 +46,7 @@ class ImageField extends FileIFrameField {
|
|||||||
$filter = create_function('$item', 'return (in_array("Folder", ClassInfo::ancestry($item->ClassName)) || in_array("Image", ClassInfo::ancestry($item->ClassName)));');
|
$filter = create_function('$item', 'return (in_array("Folder", ClassInfo::ancestry($item->ClassName)) || in_array("Image", ClassInfo::ancestry($item->ClassName)));');
|
||||||
|
|
||||||
$form = parent::EditFileForm();
|
$form = parent::EditFileForm();
|
||||||
$form->dataFieldByName('ExistingFile')->setFilterFunction($filter);
|
$form->Fields()->dataFieldByName('ExistingFile')->setFilterFunction($filter);
|
||||||
|
|
||||||
return $form;
|
return $form;
|
||||||
}
|
}
|
||||||
|
@ -454,7 +454,7 @@ class RequestHandlingTest_Form extends Form {
|
|||||||
);
|
);
|
||||||
|
|
||||||
function handleField($request) {
|
function handleField($request) {
|
||||||
return $this->dataFieldByName($request->param('FieldName'));
|
return $this->Fields()->dataFieldByName($request->param('FieldName'));
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleSubmission($request) {
|
function handleSubmission($request) {
|
||||||
|
@ -32,7 +32,7 @@ class ComplexTableFieldTest extends FunctionalTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function testCorrectNumberOfRowsInTable() {
|
function testCorrectNumberOfRowsInTable() {
|
||||||
$field = $this->manyManyForm->dataFieldByName('Players');
|
$field = $this->manyManyForm->Fields()->dataFieldByName('Players');
|
||||||
$parser = new CSSContentParser($field->FieldHolder());
|
$parser = new CSSContentParser($field->FieldHolder());
|
||||||
|
|
||||||
$this->assertEquals(count($parser->getBySelector('tbody tr')), 2, 'There are 2 players (rows) in the table');
|
$this->assertEquals(count($parser->getBySelector('tbody tr')), 2, 'There are 2 players (rows) in the table');
|
||||||
|
@ -170,11 +170,11 @@ class FormTest extends FunctionalTest {
|
|||||||
public function testFormMethodOverride() {
|
public function testFormMethodOverride() {
|
||||||
$form = $this->getStubForm();
|
$form = $this->getStubForm();
|
||||||
$form->setFormMethod('GET');
|
$form->setFormMethod('GET');
|
||||||
$this->assertNull($form->dataFieldByName('_method'));
|
$this->assertNull($form->Fields()->dataFieldByName('_method'));
|
||||||
|
|
||||||
$form = $this->getStubForm();
|
$form = $this->getStubForm();
|
||||||
$form->setFormMethod('PUT');
|
$form->setFormMethod('PUT');
|
||||||
$this->assertEquals($form->dataFieldByName('_method')->Value(), 'put',
|
$this->assertEquals($form->Fields()->dataFieldByName('_method')->Value(), 'put',
|
||||||
'PUT override in forms has PUT in hiddenfield'
|
'PUT override in forms has PUT in hiddenfield'
|
||||||
);
|
);
|
||||||
$this->assertEquals($form->FormMethod(), 'post',
|
$this->assertEquals($form->FormMethod(), 'post',
|
||||||
@ -183,7 +183,7 @@ class FormTest extends FunctionalTest {
|
|||||||
|
|
||||||
$form = $this->getStubForm();
|
$form = $this->getStubForm();
|
||||||
$form->setFormMethod('DELETE');
|
$form->setFormMethod('DELETE');
|
||||||
$this->assertEquals($form->dataFieldByName('_method')->Value(), 'delete',
|
$this->assertEquals($form->Fields()->dataFieldByName('_method')->Value(), 'delete',
|
||||||
'PUT override in forms has PUT in hiddenfield'
|
'PUT override in forms has PUT in hiddenfield'
|
||||||
);
|
);
|
||||||
$this->assertEquals($form->FormMethod(), 'post',
|
$this->assertEquals($form->FormMethod(), 'post',
|
||||||
|
@ -229,10 +229,10 @@ class TableListFieldTest extends SapphireTest {
|
|||||||
))
|
))
|
||||||
), new FieldList());
|
), new FieldList());
|
||||||
|
|
||||||
$table = $form->dataFieldByName('Tester');
|
$table = $form->Fields()->dataFieldByName('Tester');
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$table->Link('test'),
|
$table->Link('test'),
|
||||||
sprintf('TableListFieldTest_TestController/TestForm/field/Tester/test?SecurityID=%s', $form->dataFieldByName('SecurityID')->Value())
|
sprintf('TableListFieldTest_TestController/TestForm/field/Tester/test?SecurityID=%s', $form->Fields()->dataFieldByName('SecurityID')->Value())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -317,7 +317,7 @@ class TableListFieldTest extends SapphireTest {
|
|||||||
))
|
))
|
||||||
), new FieldList());
|
), new FieldList());
|
||||||
|
|
||||||
$table = $form->dataFieldByName('Tester');
|
$table = $form->Fields()->dataFieldByName('Tester');
|
||||||
$rendered = $table->FieldHolder();
|
$rendered = $table->FieldHolder();
|
||||||
|
|
||||||
$this->assertContains('A-one', $rendered);
|
$this->assertContains('A-one', $rendered);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user