From fac99f7b6b8ea1675737381ca56d850c1f9b075d Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Wed, 16 Aug 2017 13:59:41 +1200 Subject: [PATCH] FIX Alias object context in closure for PHP 5.3 compat, add test to cover it --- .../editableformfields/EditableTextField.php | 7 +++++-- .../EditableFormField/EditableTextFieldTest.php | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 tests/Model/EditableFormField/EditableTextFieldTest.php diff --git a/code/model/editableformfields/EditableTextField.php b/code/model/editableformfields/EditableTextField.php index b518446..2273d3f 100644 --- a/code/model/editableformfields/EditableTextField.php +++ b/code/model/editableformfields/EditableTextField.php @@ -61,7 +61,10 @@ class EditableTextField extends EditableFormField public function getCMSFields() { - $this->beforeUpdateCMSFields(function ($fields) { + // PHP 5.3 compat + $self = $this; + + $this->beforeUpdateCMSFields(function ($fields) use ($self) { $fields->addFieldToTab( 'Root.Main', NumericField::create( @@ -78,7 +81,7 @@ class EditableTextField extends EditableFormField DropdownField::create( 'Autocomplete', _t('EditableTextField.AUTOCOMPLETE', 'Autocomplete'), - $this->config()->get('autocomplete_options') + $self->config()->get('autocomplete_options') )->setDescription(_t( 'EditableTextField.AUTOCOMPLETE_DESCRIPTION', 'Supported browsers will attempt to populate this field automatically with the users information, use to set the value populated' diff --git a/tests/Model/EditableFormField/EditableTextFieldTest.php b/tests/Model/EditableFormField/EditableTextFieldTest.php new file mode 100644 index 0000000..19e0503 --- /dev/null +++ b/tests/Model/EditableFormField/EditableTextFieldTest.php @@ -0,0 +1,17 @@ +remove('EditableTextField', 'autocomplete_options'); + Config::inst()->update('EditableTextField', 'autocomplete_options', array('foo' => 'foo')); + + $field = new EditableTextField; + $result = $field->getCMSFields(); + + $autocompleteField = $result->fieldByName('Root.Main.Autocomplete'); + $this->assertInstanceOf('DropdownField', $autocompleteField); + $this->assertEquals(array('foo' => 'foo'), $autocompleteField->getSource()); + } +}