FIX Add friendly labels for ASC and DESC in query builder. Remove extension point in addQueryFields.

Use updateCMSFields instead
This commit is contained in:
Robbie Averill 2017-06-06 16:53:52 +12:00
parent 8208822400
commit f296c89dc0
4 changed files with 23 additions and 46 deletions

View File

@ -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:
*
* <code>
* public function updateQueryFields($result)
* {
* // Do something here
* }
* </code>
*
* @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()

View File

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

View File

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

View File

@ -1,24 +0,0 @@
<?php
/**
* Class StubDocumentSetMockExtension
*
* @package dms
*/
class StubDocumentSetMockExtension extends DataExtension implements TestOnly
{
/**
*
* For method {@link DMSDocumentSet::addQueryFields}
*
* @param FieldList $fields
*
* @return FieldList
*/
public function updateQueryFields($fields)
{
$fields->addFieldToTab('Root.QueryBuilder', new TextField('ExtendedField'));
return $fields;
}
}