NEW Allow existing document sets to be linked to pages

This commit is contained in:
Robbie Averill 2017-06-06 11:16:44 +12:00
parent d8f3685601
commit 8a7fe273a6
3 changed files with 28 additions and 1 deletions

View File

@ -20,10 +20,15 @@ class DMSSiteTreeExtension extends DataExtension
'Document Sets', 'Document Sets',
false, false,
$this->owner->DocumentSets(), //->Sort('DocumentSort'), $this->owner->DocumentSets(), //->Sort('DocumentSort'),
new GridFieldConfig_RecordEditor $config = new GridFieldConfig_RelationEditor
); );
$gridField->addExtraClass('documentsets'); $gridField->addExtraClass('documentsets');
// Only show document sets in the autocompleter that have not been assigned to a page already
$config->getComponentByType('GridFieldAddExistingAutocompleter')->setSearchList(
DMSDocumentSet::get()->filter(array('PageID' => 0))
);
$fields->addFieldToTab( $fields->addFieldToTab(
'Root.Document Sets (' . $this->owner->DocumentSets()->count() . ')', 'Root.Document Sets (' . $this->owner->DocumentSets()->count() . ')',
$gridField $gridField

View File

@ -62,6 +62,8 @@ DMSDocumentSet:
dsSaveLinkedDocuments: dsSaveLinkedDocuments:
Title: Test Set 6 Title: Test Set 6
Page: =>SiteTree.s9 Page: =>SiteTree.s9
unlinked_set:
Title: Document Set not linked
DMSDocument: DMSDocument:
d1: d1:
Filename: test-file-file-doesnt-exist-1 Filename: test-file-file-doesnt-exist-1

View File

@ -82,4 +82,24 @@ class DMSSiteTreeExtensionTest extends SapphireTest
} }
$this->assertCount(0, $siteTree->getAllDocuments()->filter('EmbargoedUntilPublished', true)); $this->assertCount(0, $siteTree->getAllDocuments()->filter('EmbargoedUntilPublished', true));
} }
/**
* Ensure that document sets that are assigned to pages to not show up in "link existing" autocomplete
* search results
*/
public function testGetRelatedDocumentsForAutocompleter()
{
$page = $this->objFromFixture('SiteTree', 's1');
$gridField = $page->getCMSFields()->fieldByName('Root.Document Sets (2).Document Sets');
$this->assertInstanceOf('GridField', $gridField);
$autocompleter = $gridField->getConfig()->getComponentByType('GridFieldAddExistingAutocompleter');
$jsonResult = $autocompleter->doSearch(
$gridField,
new SS_HTTPRequest('GET', '/', array('gridfield_relationsearch' => 'Document Set'))
);
$this->assertContains('Document Set not linked', $jsonResult);
$this->assertNotContains('Document Set 1', $jsonResult);
}
} }