mirror of
https://github.com/silverstripe/silverstripe-dms
synced 2024-10-22 14:05:56 +02:00
FIX Add friendly labels for ASC and DESC in query builder. Remove extension point in addQueryFields.
Use updateCMSFields instead
This commit is contained in:
parent
8208822400
commit
f296c89dc0
@ -194,15 +194,6 @@ class DMSDocumentSet extends DataObject
|
|||||||
/**
|
/**
|
||||||
* Adds the query fields to build the document logic to the DMSDocumentSet.
|
* 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
|
* @param FieldList $fields
|
||||||
*/
|
*/
|
||||||
public function addQueryFields($fields)
|
public function addQueryFields($fields)
|
||||||
@ -229,12 +220,19 @@ class DMSDocumentSet extends DataObject
|
|||||||
'Created' => 'Created',
|
'Created' => 'Created',
|
||||||
'Title' => 'Document title',
|
'Title' => 'Document title',
|
||||||
), 'LastEdited'),
|
), '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:'));
|
$sortedBy->setTitle(_t('DMSDocumentSet.SORTED_BY', 'Sort the document set by:'));
|
||||||
$fields->addFieldsToTab('Root.QueryBuilder', array($keyValPairs, $sortedBy));
|
$fields->addFieldsToTab('Root.QueryBuilder', array($keyValPairs, $sortedBy));
|
||||||
$this->extend('updateQueryFields', $fields);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onBeforeWrite()
|
public function onBeforeWrite()
|
||||||
|
@ -24,6 +24,8 @@ en:
|
|||||||
DMSDocumentSet:
|
DMSDocumentSet:
|
||||||
ADDDOCUMENTBUTTON: Add Document
|
ADDDOCUMENTBUTTON: Add Document
|
||||||
ADDDOCUMENTSBUTTON: Add Documents
|
ADDDOCUMENTSBUTTON: Add Documents
|
||||||
|
DIRECTION_ASCENDING: Ascending
|
||||||
|
DIRECTION_DESCENDING: Descending
|
||||||
GRIDFIELD_NOTICE: Managing documents will be available once you have created this document set.
|
GRIDFIELD_NOTICE: Managing documents will be available once you have created this document set.
|
||||||
PLURALNAME: Document Sets
|
PLURALNAME: Document Sets
|
||||||
SHOWONPAGE: Show on page
|
SHOWONPAGE: Show on page
|
||||||
|
@ -123,7 +123,6 @@ class DMSDocumentSetTest extends SapphireTest
|
|||||||
*/
|
*/
|
||||||
public function testAddQueryFields()
|
public function testAddQueryFields()
|
||||||
{
|
{
|
||||||
|
|
||||||
/** @var DMSDocumentSet $set */
|
/** @var DMSDocumentSet $set */
|
||||||
$set = $this->objFromFixture('DMSDocumentSet', 'ds6');
|
$set = $this->objFromFixture('DMSDocumentSet', 'ds6');
|
||||||
/** @var FieldList $fields */
|
/** @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'));
|
$this->assertInstanceOf('DropdownField', $dropdown);
|
||||||
$set = new DMSDocumentSet;
|
$source = $dropdown->getSource();
|
||||||
$set->addQueryFields($fields);
|
$this->assertContains('Ascending', $source);
|
||||||
|
$this->assertContains('Descending', $source);
|
||||||
$this->assertNotNull(
|
|
||||||
$fields->dataFieldByName('ExtendedField'),
|
|
||||||
'addQueryFields() is extendible as it included the field from the extension'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user