From fac99f7b6b8ea1675737381ca56d850c1f9b075d Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Wed, 16 Aug 2017 13:59:41 +1200 Subject: [PATCH 1/3] 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()); + } +} From 4adfc1b91acd3387ab45dd433815339b30a223d9 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Wed, 16 Aug 2017 14:08:56 +1200 Subject: [PATCH 2/3] Use precise dist on Travis to ensure PHP 5.3 support --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 9f1d072..d957452 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,8 @@ sudo: false language: php +dist: precise + matrix: include: - php: 5.3 From afa4e75f031ab2697d38f06b1cba48f3a6c99e0e Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Tue, 22 Aug 2017 10:11:13 +1200 Subject: [PATCH 3/3] FIX HTML or plain text toggle works across PJAX requests --- javascript/Recipient.js | 51 +++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 27 deletions(-) diff --git a/javascript/Recipient.js b/javascript/Recipient.js index 0e97c57..02eb8f4 100644 --- a/javascript/Recipient.js +++ b/javascript/Recipient.js @@ -2,35 +2,32 @@ * Email recipient behaviour. */ -(function ($) { - $(document).ready(function () { +(function($) { + $.entwine('ss', function($) { + var recipient = { + // Some fields are only visible when HTML email are being sent. + updateFormatSpecificFields: function () { + var sendPlainChecked = $('input[name="SendPlain"]').is(':checked'); - var sendPlain = $('input[name="SendPlain"]'); - var recipient = { - // Some fields are only visible when HTML email are being sent. - updateFormatSpecificFields: function () { - var sendPlainChecked = sendPlain.is(':checked'); + $('.field.toggle-html-only')[sendPlainChecked ? 'hide' : 'show'](); + $('.field.toggle-plain-only')[sendPlainChecked ? 'show' : 'hide'](); + } + }; - $(".field.toggle-html-only")[sendPlainChecked ? 'hide' : 'show'](); - $(".field.toggle-plain-only")[sendPlainChecked ? 'show' : 'hide'](); - } - }; + $('#Form_ItemEditForm .EmailRecipientForm').entwine({ + onmatch: function () { + recipient.updateFormatSpecificFields(); + }, - $.entwine('udf.recipient', function ($) { - $('#Form_ItemEditForm').entwine({ - onmatch: function () { - recipient.updateFormatSpecificFields(); - }, - onunmatch: function () { - this._super(); - } - }); + onunmatch: function () { + this._super(); + } + }); - sendPlain.entwine({ - onchange: function () { - recipient.updateFormatSpecificFields(); - } - }); - }); - }); + $('#Form_ItemEditForm .EmailRecipientForm input[name="SendPlain"]').entwine({ + onchange: function () { + recipient.updateFormatSpecificFields(); + } + }); + }); }(jQuery));