FIX Remove "Page" literal field when editing a doc set in a page context. Simplify exception test.

This commit is contained in:
Robbie Averill 2017-06-06 11:40:33 +12:00
parent d8f3685601
commit 7fb2662958
2 changed files with 25 additions and 8 deletions

View File

@ -117,8 +117,12 @@ class DMSDocumentSet extends DataObject
$gridFieldConfig->addComponent($sortableComponent); $gridFieldConfig->addComponent($sortableComponent);
} }
$field = $fields->fieldByName('Root.Main.PageID'); // Don't show which page this is if we're already editing within a page context
$field->setTitle(_t('DMSDocumentSet.SHOWONPAGE', 'Show on page')); if (Controller::curr() instanceof CMSPageEditController) {
$fields->removeByName('PageID');
} else {
$fields->fieldByName('Root.Main.PageID')->setTitle(_t('DMSDocumentSet.SHOWONPAGE', 'Show on page'));
}
$gridFieldConfig->getComponentByType('GridFieldDataColumns') $gridFieldConfig->getComponentByType('GridFieldDataColumns')
->setDisplayFields($self->getDocumentDisplayFields()) ->setDisplayFields($self->getDocumentDisplayFields())

View File

@ -194,11 +194,24 @@ class DMSDocumentSetTest extends SapphireTest
*/ */
public function testExceptionOnNoTitleGiven() public function testExceptionOnNoTitleGiven()
{ {
$set = DMSDocumentSet::create(array('Title' => '')); DMSDocumentSet::create(array('Title' => ''))->write();
try { }
$set->write();
} catch (ValidationException $e) { /**
throw $e; * Ensure that when editing in a page context that the "page" field is removed, or is labelled "Show on page"
} * otherwise
*/
public function testPageFieldRemovedWhenEditingInPageContext()
{
$set = $this->objFromFixture('DMSDocumentSet', 'ds1');
$fields = $set->getCMSFields();
$this->assertInstanceOf('DropdownField', $fields->fieldByName('Root.Main.PageID'));
$pageController = new CMSPageEditController;
$pageController->pushCurrent();
$fields = $set->getCMSFields();
$this->assertNull($fields->fieldByName('Root.Main.PageID'));
} }
} }