'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('SilverStripe\\CMS\\Model\\SiteTree'))); } parent::init(); Requirements::javascript(CMS_DIR . '/client/dist/js/bundle.js'); Requirements::javascript(CMS_DIR . '/client/dist/js/SilverStripeNavigator.js'); Requirements::css(CMS_DIR . '/client/dist/styles/bundle.css'); Requirements::customCSS($this->generatePageIconsCss()); Requirements::add_i18n_javascript(CMS_DIR . '/client/lang', false, true); CMSBatchActionHandler::register('restore', CMSBatchAction_Restore::class); CMSBatchActionHandler::register('archive', CMSBatchAction_Archive::class); CMSBatchActionHandler::register('unpublish', CMSBatchAction_Unpublish::class); CMSBatchActionHandler::register('publish', CMSBatchAction_Publish::class); } 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. * * @param SiteTree $page * @return array */ 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'), // 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 CMSPagesController::singleton()->Link(); } public function LinkPagesWithSearch() { return $this->LinkWithSearch($this->LinkPages()); } public function LinkTreeView() { return $this->LinkWithSearch($this->Link('treeview')); } public function LinkListView() { return $this->LinkWithSearch($this->Link('listview')); } public function LinkGalleryView() { return $this->LinkWithSearch($this->Link('galleryview')); } public function LinkPageEdit($id = null) { if(!$id) { $id = $this->currentPageID(); } return $this->LinkWithSearch( Controller::join_links(CMSPageEditController::singleton()->Link('show'), $id) ); } public function LinkPageSettings() { if($id = $this->currentPageID()) { return $this->LinkWithSearch( Controller::join_links(CMSPageSettingsController::singleton()->Link('show'), $id) ); } else { return null; } } public function LinkPageHistory() { if($id = $this->currentPageID()) { return $this->LinkWithSearch( Controller::join_links(CMSPageHistoryController::singleton()->Link('show'), $id) ); } else { return null; } } 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 = CMSPageAddController::singleton()->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::class, "Stage"); Versioned::prepopulate_versionnumber_cache(SiteTree::class, "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'] === 'SilverStripe\\CMS\\Controllers\\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')); $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( $dateFrom, $dateTo ); $dateGroup->setTitle(_t('CMSSearch.PAGEFILTERDATEHEADING', 'Last edited')); // Create the Field list $fields = new FieldList( $content, $pageFilter, $pageClasses, $dateGroup ); // Create the Search and Reset action $actions = new FieldList( FormAction::create('doSearch', _t('CMSMain_left_ss.APPLY_FILTER', 'Search')) ->addExtraClass('ss-ui-action-constructive'), ResetFormAction::create('clear', _t('CMSMain_left_ss.CLEAR_FILTER', 'Clear')) ); // Use