NEW pages link to document sets

This commit is contained in:
Franco Springveldt 2017-06-07 09:31:08 +12:00
parent 0368293e74
commit ce37b81c2b
3 changed files with 46 additions and 3 deletions

View File

@ -13,6 +13,11 @@ class DMSDocumentAdmin extends ModelAdmin
private static $menu_icon = 'dms/images/app_icons/drawer.png'; private static $menu_icon = 'dms/images/app_icons/drawer.png';
public function init()
{
parent::init();
Requirements::javascript(DMS_DIR . '/javascript/DMSGridField.js');
}
/** /**
* Remove the default "add" button and replace it with a customised version for DMS * Remove the default "add" button and replace it with a customised version for DMS
* *
@ -41,13 +46,29 @@ class DMSDocumentAdmin extends ModelAdmin
if ($this->modelClass === 'DMSDocument') { if ($this->modelClass === 'DMSDocument') {
$gridFieldConfig->removeComponentsByType('GridFieldAddNewButton'); $gridFieldConfig->removeComponentsByType('GridFieldAddNewButton');
$gridFieldConfig->addComponent(new DMSGridFieldAddNewButton('buttons-before-left'), 'GridFieldExportButton'); $gridFieldConfig->addComponent(
new DMSGridFieldAddNewButton('buttons-before-left'),
'GridFieldExportButton'
);
} elseif ($this->modelClass === 'DMSDocumentSet') { } elseif ($this->modelClass === 'DMSDocumentSet') {
$dataColumns = $gridFieldConfig->getComponentByType('GridFieldDataColumns'); $dataColumns = $gridFieldConfig->getComponentByType('GridFieldDataColumns');
$fields = $dataColumns->getDisplayFields($gridField); $fields = $dataColumns->getDisplayFields($gridField);
$fields = array('Title' => 'Title', 'Page.Title' => 'Page') + $fields; $fields = array('Title' => 'Title', 'Page.Title' => 'Page') + $fields;
$dataColumns->setDisplayFields($fields); $dataColumns->setDisplayFields($fields)
Requirements::add_i18n_javascript(DMS_DIR.'/javascript/lang'); ->setFieldFormatting(
array(
'Page.Title' => function ($value, $item) {
// Link a page click directly to the Document Set on the actual page
if ($page = SiteTree::get()->byID($item->PageID)) {
return sprintf(
"<a class='dms-doc-sets-link' href='%s/#Root_DocumentSets%s'>$value</a>",
$page->CMSEditLink(),
$page->DocumentSets()->count()
);
}
}
)
);
} }
return $form; return $form;

View File

@ -11,5 +11,14 @@
return false; return false;
} }
}); });
$('.ss-gridfield-item a.dms-doc-sets-link').entwine({
onclick: function (e){
// Prevent the initial flash of the gridfield's edit form
e.preventDefault();
document.location.href=this.attr('href');
return false;
}
});
}); });
}(jQuery)); }(jQuery));

View File

@ -57,4 +57,17 @@ class DMSDocumentAdminTest extends FunctionalTest
$this->assertContains('Home Test Page', $result); $this->assertContains('Home Test Page', $result);
$this->assertContains('About Us Test Page', $result); $this->assertContains('About Us Test Page', $result);
} }
/**
* Checks that the document sets GridField has a data column which links to the DocumentSets tab on
* the actual page in the CMS
*/
public function testDocumentSetsGridFieldHasLinkToCMSPageEditor()
{
$result = (string)$this->get('admin/documents/DMSDocumentSet')->getBody();
$this->assertContains(
"<a class='dms-doc-sets-link'",
$result
);
}
} }