'Boolean',
'AddForm' => 'HTMLFragment',
'LinkPages' => 'Text',
'Link' => 'Text',
'ListViewForm' => 'HTMLFragment',
'ExtraTreeTools' => 'HTMLFragment',
'SiteTreeHints' => 'HTMLFragment',
'SecurityID' => 'Text',
'SiteTreeAsUL' => 'HTMLFragment',
);
public function init() {
// set reading lang
if(SiteTree::has_extension('Translatable') && !$this->getRequest()->isAjax()) {
Translatable::choose_site_locale(array_keys(Translatable::get_existing_content_languages('SiteTree')));
}
parent::init();
Requirements::css(CMS_DIR . '/client/dist/styles/bundle.css');
Requirements::customCSS($this->generatePageIconsCss());
Requirements::add_i18n_javascript(CMS_DIR . '/client/lang', false, true);
Requirements::javascript(CMS_DIR . '/client/dist/js/bundle-legacy.js', [
'provides' => [
CMS_DIR . '/client/dist/js/CMSMain.AddForm.js',
CMS_DIR . '/client/dist/js/CMSMain.EditForm.js',
CMS_DIR . '/client/dist/js/CMSMain.js',
CMS_DIR . '/client/dist/js/CMSMain.Tree.js',
CMS_DIR . '/client/dist/js/CMSPageHistoryController.js',
CMS_DIR . '/client/dist/js/RedirectorPage.js',
CMS_DIR . '/client/dist/js/SilverStripeNavigator.js',
CMS_DIR . '/client/dist/js/SiteTreeURLSegmentField.js'
]
]);
CMSBatchActionHandler::register('publish', 'CMSBatchAction_Publish');
CMSBatchActionHandler::register('unpublish', 'CMSBatchAction_Unpublish');
CMSBatchActionHandler::register('delete', 'CMSBatchAction_Delete');
CMSBatchActionHandler::register('archive', 'CMSBatchAction_Archive');
CMSBatchActionHandler::register('restore', 'CMSBatchAction_Restore');
}
public function index($request) {
// In case we're not showing a specific record, explicitly remove any session state,
// to avoid it being highlighted in the tree, and causing an edit form to show.
if(!$request->param('Action')) $this->setCurrentPageId(null);
return parent::index($request);
}
public function getResponseNegotiator() {
$negotiator = parent::getResponseNegotiator();
$controller = $this;
$negotiator->setCallback('ListViewForm', function() use(&$controller) {
return $controller->ListViewForm()->forTemplate();
});
return $negotiator;
}
/**
* If this is set to true, the "switchView" context in the
* template is shown, with links to the staging and publish site.
*
* @return boolean
*/
public function ShowSwitchView() {
return true;
}
/**
* Overloads the LeftAndMain::ShowView. Allows to pass a page as a parameter, so we are able
* to switch view also for archived versions.
*/
public function SwitchView($page = null) {
if(!$page) {
$page = $this->currentPage();
}
if($page) {
$nav = SilverStripeNavigator::get_for_record($page);
return $nav['items'];
}
}
//------------------------------------------------------------------------------------------//
// Main controllers
//------------------------------------------------------------------------------------------//
// Main UI components
/**
* Override {@link LeftAndMain} Link to allow blank URL segment for CMSMain.
*
* @param string|null $action Action to link to.
* @return string
*/
public function Link($action = null) {
$link = Controller::join_links(
AdminRootController::admin_url(),
$this->stat('url_segment', true), // in case we want to change the segment
'/', // trailing slash needed if $action is null!
"$action"
);
$this->extend('updateLink', $link);
return $link;
}
public function LinkPages() {
return singleton('CMSPagesController')->Link();
}
public function LinkPagesWithSearch() {
return $this->LinkWithSearch($this->LinkPages());
}
public function LinkTreeView() {
return $this->LinkWithSearch(singleton('CMSMain')->Link('treeview'));
}
public function LinkListView() {
return $this->LinkWithSearch(singleton('CMSMain')->Link('listview'));
}
public function LinkGalleryView() {
return $this->LinkWithSearch(singleton('CMSMain')->Link('galleryview'));
}
public function LinkPageEdit($id = null) {
if(!$id) $id = $this->currentPageID();
return $this->LinkWithSearch(
Controller::join_links(singleton('CMSPageEditController')->Link('show'), $id)
);
}
public function LinkPageSettings() {
if($id = $this->currentPageID()) {
return $this->LinkWithSearch(
Controller::join_links(singleton('CMSPageSettingsController')->Link('show'), $id)
);
}
}
public function LinkPageHistory() {
if($id = $this->currentPageID()) {
return $this->LinkWithSearch(
Controller::join_links(singleton('CMSPageHistoryController')->Link('show'), $id)
);
}
}
public function LinkWithSearch($link) {
// Whitelist to avoid side effects
$params = array(
'q' => (array)$this->getRequest()->getVar('q'),
'ParentID' => $this->getRequest()->getVar('ParentID')
);
$link = Controller::join_links(
$link,
array_filter(array_values($params)) ? '?' . http_build_query($params) : null
);
$this->extend('updateLinkWithSearch', $link);
return $link;
}
public function LinkPageAdd($extra = null, $placeholders = null) {
$link = singleton("CMSPageAddController")->Link();
$this->extend('updateLinkPageAdd', $link);
if($extra) {
$link = Controller::join_links ($link, $extra);
}
if($placeholders) {
$link .= (strpos($link, '?') === false ? "?$placeholders" : "&$placeholders");
}
return $link;
}
/**
* @return string
*/
public function LinkPreview() {
$record = $this->getRecord($this->currentPageID());
$baseLink = Director::absoluteBaseURL();
if ($record && $record instanceof Page) {
// if we are an external redirector don't show a link
if ($record instanceof RedirectorPage && $record->RedirectionType == 'External') {
$baseLink = false;
}
else {
$baseLink = $record->Link('?stage=Stage');
}
}
return $baseLink;
}
/**
* Return the entire site tree as a nested set of ULs
*/
public function SiteTreeAsUL() {
// Pre-cache sitetree version numbers for querying efficiency
Versioned::prepopulate_versionnumber_cache("SiteTree", "Stage");
Versioned::prepopulate_versionnumber_cache("SiteTree", "Live");
$html = $this->getSiteTreeFor($this->stat('tree_class'));
$this->extend('updateSiteTreeAsUL', $html);
return $html;
}
/**
* @return boolean
*/
public function TreeIsFiltered() {
$query = $this->getRequest()->getVar('q');
if (!$query || (count($query) === 1 && isset($query['FilterClass']) && $query['FilterClass'] === 'CMSSiteTreeFilter_Search')) {
return false;
}
return true;
}
public function ExtraTreeTools() {
$html = '';
$this->extend('updateExtraTreeTools', $html);
return $html;
}
/**
* Returns a Form for page searching for use in templates.
*
* Can be modified from a decorator by a 'updateSearchForm' method
*
* @return Form
*/
public function SearchForm() {
// Create the fields
$content = new TextField('q[Term]', _t('CMSSearch.FILTERLABELTEXT', 'Search'));
$dateHeader = new HeaderField('q[Date]', _t('CMSSearch.PAGEFILTERDATEHEADING', 'Last edited'), 4);
$dateFrom = new DateField(
'q[LastEditedFrom]',
_t('CMSSearch.FILTERDATEFROM', 'From')
);
$dateFrom->setConfig('showcalendar', true);
$dateTo = new DateField(
'q[LastEditedTo]',
_t('CMSSearch.FILTERDATETO', 'To')
);
$dateTo->setConfig('showcalendar', true);
$pageFilter = new DropdownField(
'q[FilterClass]',
_t('CMSMain.PAGES', 'Page status'),
CMSSiteTreeFilter::get_all_filters()
);
$pageClasses = new DropdownField(
'q[ClassName]',
_t('CMSMain.PAGETYPEOPT', 'Page type', 'Dropdown for limiting search to a page type'),
$this->getPageTypes()
);
$pageClasses->setEmptyString(_t('CMSMain.PAGETYPEANYOPT','Any'));
// Group the Datefields
$dateGroup = new FieldGroup(
$dateHeader,
$dateFrom,
$dateTo
);
$dateGroup->setFieldHolderTemplate('FieldGroup_DefaultFieldHolder')->addExtraClass('stacked');
// Create the Field list
$fields = new FieldList(
$content,
$dateGroup,
$pageFilter,
$pageClasses
);
// Create the Search and Reset action
$actions = new FieldList(
FormAction::create('doSearch', _t('CMSMain_left_ss.APPLY_FILTER', 'Search'))
->addExtraClass('ss-ui-action-constructive'),
Object::create('ResetFormAction', 'clear', _t('CMSMain_left_ss.CLEAR_FILTER', 'Clear'))
);
// Use