API-CHANGE: adding ability to show/hide the Document tab on specific pages

This commit is contained in:
Julian Seidenberg 2012-11-22 14:15:13 +13:00
parent 18c2081be7
commit a9f9e7111a
2 changed files with 29 additions and 7 deletions

View File

@ -1,5 +1,13 @@
<?php
DMSDocument_versions::$enable_versions = true;
DMSSiteTreeExtension::show_documents_tab(); //show the Documents tab on all pages
DMSSiteTreeExtension::no_documents_tab(); //and don't exclude it from any pages
define('DMS_DIR', 'dms');
if (!file_exists(BASE_PATH . DIRECTORY_SEPARATOR . DMS_DIR)) user_error("DMS directory named incorrectly. Please install the DMS module into a folder named: ".DMS_DIR);
Object::add_extension('SiteTree','DMSSiteTreeExtension');
@ -8,10 +16,7 @@ CMSMenu::remove_menu_item('DMSDocumentAddController');
ShortcodeParser::get('default')->register('dms_document_link', array('DMSDocument_Controller', 'dms_link_shortcode_handler'));
DMSDocument_versions::$enable_versions = true;
if (DMSDocument_versions::$enable_versions) {
//using the same db relations for the versioned documents, as for the actual documents
Config::inst()->update('DMSDocument_versions', 'db', DMSDocument::$db);
}
}

View File

@ -5,15 +5,16 @@ class DMSSiteTreeExtension extends DataExtension {
'Documents' => 'DMSDocument'
);
static $noDocumentsList = array(
);
static $noDocumentsList = array();
static $showDocumentsList = array();
/**
* Do not show the documents tab on the array of pages set here
* @static
* @param $mixed Array of page types to not show the Documents tab on
*/
static function no_documents_tab($array) {
static function no_documents_tab($array = array()) {
if (empty($array)) return;
if (is_array($array)) {
self::$noDocumentsList = $array;
} else {
@ -21,9 +22,25 @@ class DMSSiteTreeExtension extends DataExtension {
}
}
/**
* Only show the documents tab on the list of pages set here. Any pages set in the no_documents_tab array will
* still not be shown. If this isn't called, or if it is called with an empty array, all pages will get Document tabs.
* @static
* @param $array Array of page types to show the Documents tab on
*/
static function show_documents_tab($array = array()) {
if (empty($array)) return;
if (is_array($array)) {
self::$showDocumentsList = $array;
} else {
self::$showDocumentsList = array($array);
}
}
function updateCMSFields(FieldList $fields){
//prevent certain pages from having a Document tab in the CMS
if (in_array($this->owner->ClassName,self::$noDocumentsList)) return;
if (count(self::$showDocumentsList) > 0 && !in_array($this->owner->ClassName,self::$showDocumentsList)) return;
//javascript to customize the grid field for the DMS document (overriding entwine in FRAMEWORK_DIR.'/javascript/GridField.js'
Requirements::javascript(DMS_DIR.'/javascript/DMSGridField.js');