From f296c89dc07c235c4a04e0477307285e857ad014 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Tue, 6 Jun 2017 16:53:52 +1200 Subject: [PATCH] FIX Add friendly labels for ASC and DESC in query builder. Remove extension point in addQueryFields. Use updateCMSFields instead --- code/model/DMSDocumentSet.php | 20 ++++++++--------- lang/en.yml | 2 ++ tests/DMSDocumentSetTest.php | 23 ++++++++++---------- tests/Stub/StubDocumentSetMockExtension.php | 24 --------------------- 4 files changed, 23 insertions(+), 46 deletions(-) delete mode 100644 tests/Stub/StubDocumentSetMockExtension.php diff --git a/code/model/DMSDocumentSet.php b/code/model/DMSDocumentSet.php index 1b5e645..b9588b5 100644 --- a/code/model/DMSDocumentSet.php +++ b/code/model/DMSDocumentSet.php @@ -194,15 +194,6 @@ class DMSDocumentSet extends DataObject /** * Adds the query fields to build the document logic to the DMSDocumentSet. * - * To extend use the following from within an Extension subclass: - * - * - * public function updateQueryFields($result) - * { - * // Do something here - * } - * - * * @param FieldList $fields */ public function addQueryFields($fields) @@ -229,12 +220,19 @@ class DMSDocumentSet extends DataObject 'Created' => 'Created', 'Title' => 'Document title', ), 'LastEdited'), - DropdownField::create('SortByDirection', '', $this->dbObject('SortByDirection')->enumValues(), 'DESC'), + DropdownField::create( + 'SortByDirection', + '', + array( + 'DESC' => _t('DMSDocumentSet.DIRECTION_DESCENDING', 'Descending'), + 'ASC' => _t('DMSDocumentSet.DIRECTION_ASCENDING', 'Ascending') + ), + 'DESC' + ), )); $sortedBy->setTitle(_t('DMSDocumentSet.SORTED_BY', 'Sort the document set by:')); $fields->addFieldsToTab('Root.QueryBuilder', array($keyValPairs, $sortedBy)); - $this->extend('updateQueryFields', $fields); } public function onBeforeWrite() diff --git a/lang/en.yml b/lang/en.yml index 39ea8cb..db21441 100644 --- a/lang/en.yml +++ b/lang/en.yml @@ -24,6 +24,8 @@ en: DMSDocumentSet: ADDDOCUMENTBUTTON: Add Document ADDDOCUMENTSBUTTON: Add Documents + DIRECTION_ASCENDING: Ascending + DIRECTION_DESCENDING: Descending GRIDFIELD_NOTICE: Managing documents will be available once you have created this document set. PLURALNAME: Document Sets SHOWONPAGE: Show on page diff --git a/tests/DMSDocumentSetTest.php b/tests/DMSDocumentSetTest.php index c2dadf1..deb32e9 100644 --- a/tests/DMSDocumentSetTest.php +++ b/tests/DMSDocumentSetTest.php @@ -123,7 +123,6 @@ class DMSDocumentSetTest extends SapphireTest */ public function testAddQueryFields() { - /** @var DMSDocumentSet $set */ $set = $this->objFromFixture('DMSDocumentSet', 'ds6'); /** @var FieldList $fields */ @@ -141,19 +140,21 @@ class DMSDocumentSetTest extends SapphireTest ); } - public function testAddQueryFieldsIsExtensible() + /** + * Ensure that the "direction" dropdown field has user friendly field labels + */ + public function testQueryBuilderDirectionFieldHasFriendlyLabels() { + $fields = $this->objFromFixture('DMSDocumentSet', 'ds1')->getCMSFields(); - DMSDocumentSet::add_extension('StubDocumentSetMockExtension'); + $dropdown = $fields->fieldByName('Root.QueryBuilder')->FieldList()->filterByCallback(function ($field) { + return $field instanceof FieldGroup; + })->first()->fieldByName('SortByDirection'); - $fields = new FieldList(new TabSet('Root')); - $set = new DMSDocumentSet; - $set->addQueryFields($fields); - - $this->assertNotNull( - $fields->dataFieldByName('ExtendedField'), - 'addQueryFields() is extendible as it included the field from the extension' - ); + $this->assertInstanceOf('DropdownField', $dropdown); + $source = $dropdown->getSource(); + $this->assertContains('Ascending', $source); + $this->assertContains('Descending', $source); } /** diff --git a/tests/Stub/StubDocumentSetMockExtension.php b/tests/Stub/StubDocumentSetMockExtension.php deleted file mode 100644 index 78dd2e9..0000000 --- a/tests/Stub/StubDocumentSetMockExtension.php +++ /dev/null @@ -1,24 +0,0 @@ -addFieldToTab('Root.QueryBuilder', new TextField('ExtendedField')); - - return $fields; - } -}