mirror of
https://github.com/silverstripe/silverstripe-dms
synced 2024-10-22 14:05:56 +02:00
NEW Add column to document set GridField to show whether added manually or not
This commit is contained in:
parent
fb989de12b
commit
84e1d3ff80
@ -9,7 +9,6 @@
|
||||
*/
|
||||
class DMSDocumentSet extends DataObject
|
||||
{
|
||||
|
||||
private static $db = array(
|
||||
'Title' => 'Varchar(255)',
|
||||
'KeyValuePairs' => 'Text',
|
||||
@ -111,11 +110,17 @@ class DMSDocumentSet extends DataObject
|
||||
}
|
||||
|
||||
$gridFieldConfig->getComponentByType('GridFieldDataColumns')
|
||||
->setDisplayFields(DMSDocument::create()->config()->get('display_fields'))
|
||||
->setDisplayFields($self->getDocumentDisplayFields())
|
||||
->setFieldCasting(array('LastEdited' => 'Datetime->Ago'))
|
||||
->setFieldFormatting(
|
||||
array(
|
||||
'FilenameWithoutID' => '<a target=\'_blank\' class=\'file-url\' href=\'$Link\'>$FilenameWithoutID</a>',
|
||||
'BelongsToSet' => function ($value) {
|
||||
if ($value) {
|
||||
return _t('DMSDocumentSet.MANUAL', 'Manually');
|
||||
}
|
||||
return _t('DMSDocumentSet.QUERYBUILDER', 'Query Builder');
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
@ -254,4 +259,17 @@ class DMSDocumentSet extends DataObject
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Customise the display fields for the documents GridField
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDocumentDisplayFields()
|
||||
{
|
||||
return array_merge(
|
||||
(array) DMSDocument::create()->config()->get('display_fields'),
|
||||
array('BelongsToSet' => _t('DMSDocumentSet.ADDEDMETHOD', 'Added'))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -84,6 +84,41 @@ class DMSDocumentSetTest extends SapphireTest
|
||||
$this->$sortableAssertion($config->getComponentByType('GridFieldSortableRows'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure that the display fields for the documents GridField can be returned
|
||||
*/
|
||||
public function testGetDocumentDisplayFields()
|
||||
{
|
||||
$document = $this->objFromFixture('DMSDocumentSet', 'ds1');
|
||||
$this->assertInternalType('array', $document->getDocumentDisplayFields());
|
||||
|
||||
Config::inst()->update('DMSDocument', 'display_fields', array('apple' => 'Apple', 'orange' => 'Orange'));
|
||||
$displayFields = $document->getDocumentDisplayFields();
|
||||
$this->assertContains('Apple', $displayFields);
|
||||
$this->assertContains('Orange', $displayFields);
|
||||
$this->assertArrayHasKey('BelongsToSet', $displayFields);
|
||||
$this->assertContains('Added', $displayFields);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests to ensure that the callback for formatting BelongsToSet will return a nice label for the user
|
||||
*/
|
||||
public function testNiceFormattingForBelongsToSetInGridField()
|
||||
{
|
||||
$fieldFormatting = $this->objFromFixture('DMSDocumentSet', 'ds1')
|
||||
->getCMSFields()
|
||||
->fieldByName('Root.Main.Documents')
|
||||
->getConfig()
|
||||
->getComponentByType('GridFieldDataColumns')
|
||||
->getFieldFormatting();
|
||||
|
||||
$this->assertArrayHasKey('BelongsToSet', $fieldFormatting);
|
||||
$this->assertTrue(is_callable($fieldFormatting['BelongsToSet']));
|
||||
|
||||
$this->assertSame('Manually', $fieldFormatting['BelongsToSet'](1));
|
||||
$this->assertSame('Query Builder', $fieldFormatting['BelongsToSet'](0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that query fields can be added to the gridfield
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user