diff --git a/code/controllers/AssetAdmin.php b/code/controllers/AssetAdmin.php index 31be0c69..6cc34ac7 100644 --- a/code/controllers/AssetAdmin.php +++ b/code/controllers/AssetAdmin.php @@ -211,8 +211,8 @@ JS // List view $fields->addFieldsToTab('Root.ListView', array( - $actionsComposite = Object::create('CompositeField', - Object::create('CompositeField', + $actionsComposite = CompositeField::create( + CompositeField::create( $uploadBtn, $addFolderBtn, $syncButton //TODO: add this into a batch actions menu as in https://github.com/silverstripe/silverstripe-design/raw/master/Design/ss3-ui_files-manager-list-view.jpg @@ -255,7 +255,7 @@ JS 'EditForm' => $this->AddForm() )); - if($this->isAjax()) { + if($request->isAjax()) { // Rendering is handled by template, which will call EditForm() eventually $content = $obj->renderWith($this->getTemplatesWithSuffix('_Content')); } else { @@ -311,7 +311,7 @@ JS $fields = $context->getSearchFields(); $actions = new FieldList( - Object::create('ResetFormAction', 'clear', _t('CMSMain_left.ss.CLEAR', 'Clear')) + ResetFormAction::create('clear', _t('CMSMain_left.ss.CLEAR', 'Clear')) ->addExtraClass('ss-ui-action-minor'), FormAction::create('doSearch', _t('CMSMain_left.ss.SEARCH', 'Search')) ); diff --git a/code/controllers/CMSFileAddController.php b/code/controllers/CMSFileAddController.php index 28f2b735..4d4a6e58 100644 --- a/code/controllers/CMSFileAddController.php +++ b/code/controllers/CMSFileAddController.php @@ -9,7 +9,7 @@ class CMSFileAddController extends LeftAndMain { // public function upload($request) { // $formHtml = $this->renderWith(array('AssetAdmin_UploadContent')); -// if($this->isAjax()) { +// if($request->isAjax()) { // return $formHtml; // } else { // return $this->customise(array( @@ -57,7 +57,7 @@ class CMSFileAddController extends LeftAndMain { $folder = $this->currentPage(); - $uploadField = Object::create('UploadField', 'AssetUploadField', ''); + $uploadField = UploadField::create('AssetUploadField', ''); $uploadField->setConfig('previewMaxWidth', 40); $uploadField->setConfig('previewMaxHeight', 30); $uploadField->addExtraClass('ss-assetuploadfield'); diff --git a/code/controllers/CMSMain.php b/code/controllers/CMSMain.php index 52c5203a..8015988a 100644 --- a/code/controllers/CMSMain.php +++ b/code/controllers/CMSMain.php @@ -49,7 +49,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr public function init() { // set reading lang - if(Object::has_extension('SiteTree', 'Translatable') && !$this->isAjax()) { + if(Object::has_extension('SiteTree', 'Translatable') && !$this->request->isAjax()) { Translatable::choose_site_locale(array_keys(Translatable::get_existing_content_languages('SiteTree'))); } @@ -141,7 +141,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr // Include custom CSS for tree icons inline, as the tree might be loaded // via Ajax, in which case we can't inject it into the HTML header easily through the HTTP response. $css = $this->generateTreeStylingCSS(); - if($this->isAjax()) { + if($this->request->isAjax()) { $html .= "\n"; } else { Requirements::customCSS($css); @@ -202,7 +202,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr $dateTo->setConfig('showcalendar', true); $actions = new FieldList( - Object::create('ResetFormAction', 'clear', _t('CMSMain_left.ss.CLEAR', 'Clear')) + ResetFormAction::create('clear', _t('CMSMain_left.ss.CLEAR', 'Clear')) ->addExtraClass('ss-ui-action-minor'), FormAction::create('doSearch', _t('CMSMain_left.ss.SEARCH', 'Search')) ); @@ -243,7 +243,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr * @return String Serialized JSON */ public function SiteTreeHints() { - $classes = ClassInfo::subclassesFor( $this->stat('tree_class') ); + $classes = ClassInfo::subclassesFor( $this->stat('tree_class') ); $def['Root'] = array(); $def['Root']['disallowedParents'] = array(); @@ -257,6 +257,26 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr // SiteTree::allowedChildren() returns null rather than an empty array if SiteTree::allowed_chldren == 'none' if($allowedChildren == null) $allowedChildren = array(); + + // Exclude SiteTree from possible Children + $possibleChildren = array_diff($allowedChildren, array("SiteTree")); + + // Find i18n - names and build allowed children array + foreach($possibleChildren as $child) { + $instance = singleton($child); + + if($instance instanceof HiddenClass) continue; + + if(!$instance->canCreate()) continue; + + // skip this type if it is restricted + if($instance->stat('need_permission') && !$this->can(singleton($class)->stat('need_permission'))) continue; + + $title = $instance->i18n_singular_name(); + + $def[$class]['allowedChildren'][] = array("ssclass" => $child, "ssname" => $title); + } + $allowedChildren = array_keys(array_diff($classes, $allowedChildren)); if($allowedChildren) $def[$class]['disallowedChildren'] = $allowedChildren; @@ -266,6 +286,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr $def[$class]['defaultChild'] = $defaultChild; $defaultParent = $obj->defaultParent(); + $parent = SiteTree::get_by_link($defaultParent); $id = $parent ? $parent->id : null; @@ -370,7 +391,6 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr } $result->sort('AddAction'); - return $result; } @@ -685,20 +705,12 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr $record->Title ) ); - - // Reload form, data and actions might have changed - $form = $this->getEditForm($record->ID); } else { $this->response->addHeader('X-Status', _t('LeftAndMain.SAVEDUP')); - - // Reload form, data and actions might have changed - $form = $this->getEditForm($record->ID); } - - return $form->forTemplate(); - } - + return $this->getResponseNegotiator()->respond($this->request); + } /** * @uses LeftAndMainExtension->augmentNewSiteTreeItem() @@ -836,9 +848,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr ) ); - $form = $this->getEditForm($record->ID); - - return $form->forTemplate(); + return $this->getResponseNegotiator()->respond($this->request); } /** @@ -890,10 +900,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr sprintf(_t('CMSMain.REMOVEDPAGE',"Removed '%s' from the published site"),$record->Title) ); - // Reload form, data and actions might have changed - $form = $this->getEditForm($record->ID); - - return $form->forTemplate(); + return $this->getResponseNegotiator()->respond($this->request); } /** @@ -1042,10 +1049,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr ) ); - // Reload form, data and actions might have changed - $form = $this->getEditForm($restoredPage->ID); - - return $form->forTemplate(); + return $this->getResponseNegotiator()->respond($this->request); } function duplicate($request) { diff --git a/code/controllers/CMSPageAddController.php b/code/controllers/CMSPageAddController.php index 95cdbb03..2caa06a0 100644 --- a/code/controllers/CMSPageAddController.php +++ b/code/controllers/CMSPageAddController.php @@ -16,6 +16,18 @@ class CMSPageAddController extends CMSPageEditController { * @return Form */ function AddForm() { + // If request send from rightclick-submenu, directly add Page + if(($pageType = $this->request->getVar('Type')) && ($parentID = $this->request->getVar('ParentID'))) { + $data = array( + "PageType" => (string)$pageType, + "ParentID" => $parentID, + "ParentModeField" => "child" + ); + $this->doAdd($data, null); + return; + } + + $record = $this->currentPage(); $pageTypes = array(); @@ -89,7 +101,7 @@ class CMSPageAddController extends CMSPageEditController { if($parentID = $this->request->getVar('ParentID')) { $form->Fields()->dataFieldByName('ParentID')->setValue((int)$parentID); } - + return $form; } diff --git a/code/controllers/CMSPageHistoryController.php b/code/controllers/CMSPageHistoryController.php index e1306a54..25ad3e9f 100644 --- a/code/controllers/CMSPageHistoryController.php +++ b/code/controllers/CMSPageHistoryController.php @@ -27,7 +27,7 @@ class CMSPageHistoryController extends CMSMain { function show($request) { $form = $this->ShowVersionForm($request->param('VersionID')); - if($this->isAjax()) { + if($request->isAjax()) { if($form) $content = $form->forTemplate(); else $content = $this->renderWith($this->getTemplatesWithSuffix('_Content')); } else { @@ -44,7 +44,7 @@ class CMSPageHistoryController extends CMSMain { $request->param('VersionID'), $request->param('OtherVersionID') ); - if($this->isAjax()) { + if($request->isAjax()) { $content = $form->forTemplate(); } else { $content = $this->customise(array('EditForm' => $form))->renderWith($this->getViewer('show')); @@ -258,7 +258,7 @@ class CMSPageHistoryController extends CMSMain { $form = $this->CompareVersionsForm($version1, $version2); // javascript solution, render into template - if($this->isAjax()) { + if($this->request->isAjax()) { return $this->customise(array( "EditForm" => $form ))->renderWith(array( @@ -293,7 +293,7 @@ class CMSPageHistoryController extends CMSMain { if(!$versionID) return; - if($this->isAjax()) { + if($request->isAjax()) { return $this->customise(array( "EditForm" => $this->ShowVersionForm($versionID) ))->renderWith(array( diff --git a/code/controllers/CMSSettingsController.php b/code/controllers/CMSSettingsController.php index b73dbb7c..b0ab5519 100644 --- a/code/controllers/CMSSettingsController.php +++ b/code/controllers/CMSSettingsController.php @@ -9,7 +9,7 @@ class CMSSettingsController extends CMSMain { /** * @return Form */ - function getEditForm($id = null) { + function getEditForm($id = null, $fields = null) { $siteConfig = SiteConfig::current_site_config(); $fields = $siteConfig->getCMSFields(); @@ -54,7 +54,7 @@ class CMSSettingsController extends CMSMain { return false; } - function Breadcrumbs() { + function Breadcrumbs($unlinked = false) { return new ArrayList(array( new ArrayData(array( 'Title' => $this->SectionTitle(), @@ -63,4 +63,4 @@ class CMSSettingsController extends CMSMain { )); } -} \ No newline at end of file +} diff --git a/code/controllers/ContentController.php b/code/controllers/ContentController.php index 872f12cf..a4a49205 100644 --- a/code/controllers/ContentController.php +++ b/code/controllers/ContentController.php @@ -133,7 +133,7 @@ class ContentController extends Controller { * * @return SS_HTTPResponse */ - public function handleRequest(SS_HTTPRequest $request, DataModel $model) { + public function handleRequest(SS_HTTPRequest $request, DataModel $model = null) { $child = null; $action = $request->param('Action'); $this->setModel($model); @@ -376,7 +376,7 @@ HTML; } else { if($date = Versioned::current_archived_date()) { Requirements::css(CMS_DIR . '/css/SilverStripeNavigator.css'); - $dateObj = Object::create('Datetime', $date, null); + $dateObj = Datetime::create($date, null); // $dateObj->setVal($date); return "
"; } @@ -526,4 +526,4 @@ HTML "Content" => $content, ); } -} \ No newline at end of file +} diff --git a/code/controllers/RootURLController.php b/code/controllers/RootURLController.php index 4200afcf..b118da3e 100644 --- a/code/controllers/RootURLController.php +++ b/code/controllers/RootURLController.php @@ -104,7 +104,7 @@ class RootURLController extends Controller { * @param SS_HTTPRequest $request * @return SS_HTTPResponse */ - public function handleRequest(SS_HTTPRequest $request, DataModel $model) { + public function handleRequest(SS_HTTPRequest $request, DataModel $model = null) { self::$is_at_root = true; $this->setModel($model); diff --git a/code/controllers/SilverStripeNavigator.php b/code/controllers/SilverStripeNavigator.php index 1c3acb45..b3ba5802 100644 --- a/code/controllers/SilverStripeNavigator.php +++ b/code/controllers/SilverStripeNavigator.php @@ -193,7 +193,7 @@ class SilverStripeNavigatorItem_CMSLink extends SilverStripeNavigatorItem { return (Controller::curr() instanceof CMSMain); } - function canView() { + function canView($member = null) { // Don't show in CMS return !(Controller::curr() instanceof CMSMain); } @@ -223,7 +223,7 @@ class SilverStripeNavigatorItem_StageLink extends SilverStripeNavigatorItem { return Controller::join_links($this->record->AbsoluteLink(), '?stage=Stage'); } - function canView() { + function canView($member = null) { return ($this->record->hasExtension('Versioned') && $this->getDraftPage()); } @@ -267,7 +267,7 @@ class SilverStripeNavigatorItem_LiveLink extends SilverStripeNavigatorItem { return Controller::join_links($this->record->AbsoluteLink(), '?stage=Live'); } - function canView() { + function canView($member = null) { return ($this->record->hasExtension('Versioned') && $this->getLivePage()); } @@ -299,7 +299,7 @@ class SilverStripeNavigatorItem_ArchiveLink extends SilverStripeNavigatorItem { function getMessage() { if($date = Versioned::current_archived_date()) { - $dateObj = Object::create('Datetime'); + $dateObj = Datetime::create(); $dateObj->setValue($date); return " "; } @@ -309,7 +309,7 @@ class SilverStripeNavigatorItem_ArchiveLink extends SilverStripeNavigatorItem { return $this->record->AbsoluteLink() . '?archiveDate=' . $date; } - function canView() { + function canView($member = null) { return ($this->record->hasExtension('Versioned') && $this->isArchived()); } diff --git a/code/model/ErrorPage.php b/code/model/ErrorPage.php index 0cd7342d..d8973b92 100644 --- a/code/model/ErrorPage.php +++ b/code/model/ErrorPage.php @@ -22,6 +22,8 @@ class ErrorPage extends Page { "ShowInSearch" => 0 ); + static $allowed_children = array(); + static $description = 'Custom content for different error cases (e.g. "Page not found")'; protected static $static_filepath = ASSETS_PATH; @@ -50,7 +52,7 @@ class ErrorPage extends Page { $response = new SS_HTTPResponse(); $response->setStatusCode($statusCode); - $response->setBody(file_get_contents($cachedPath)); + $response->setBody(file_get_contents($cachedPath)); return $response; } @@ -127,8 +129,8 @@ class ErrorPage extends Page { } } - function getCMSFields() { - $fields = parent::getCMSFields(); + function getCMSFields($params = null) { + $fields = parent::getCMSFields($params); $fields->addFieldToTab( "Root.Main", diff --git a/code/model/RedirectorPage.php b/code/model/RedirectorPage.php index 1fe2082e..9d5c30fe 100644 --- a/code/model/RedirectorPage.php +++ b/code/model/RedirectorPage.php @@ -27,6 +27,8 @@ class RedirectorPage extends Page { static $many_many = array( ); + static $allowed_children = array(); + /** * Returns this page if the redirect is external, otherwise * returns the target page. @@ -115,7 +117,7 @@ class RedirectorPage extends Page { } } - function getCMSFields() { + function getCMSFields($params = null) { Requirements::javascript(SAPPHIRE_DIR . "/javascript/RedirectorPage.js"); $fields = parent::getCMSFields(); @@ -180,4 +182,4 @@ class RedirectorPage_Controller extends Page_Controller { _t('RedirectorPage.HASBEENSETUP', 'A redirector page has been set up without anywhere to redirect to.') . ""; } -} \ No newline at end of file +} diff --git a/code/model/SiteConfig.php b/code/model/SiteConfig.php index 1d9d537b..0a9d2d12 100644 --- a/code/model/SiteConfig.php +++ b/code/model/SiteConfig.php @@ -41,7 +41,7 @@ class SiteConfig extends DataObject implements PermissionProvider { * * @return FieldList */ - function getCMSFields() { + function getCMSFields($params = null) { Requirements::javascript(CMS_DIR . "/javascript/SitetreeAccess.js"); $groupsMap = DataList::create('Group')->map('ID', 'Breadcrumbs')->toArray(); @@ -56,13 +56,13 @@ class SiteConfig extends DataObject implements PermissionProvider { ), $tabAccess = new Tab('Access', $viewersOptionsField = new OptionsetField("CanViewType", _t('SiteConfig.VIEWHEADER', "Who can view pages on this site?")), - $viewerGroupsField = Object::create('ListboxField', "ViewerGroups", _t('SiteTree.VIEWERGROUPS', "Viewer Groups")) + $viewerGroupsField = ListboxField::create("ViewerGroups", _t('SiteTree.VIEWERGROUPS', "Viewer Groups")) ->setMultiple(true)->setSource($groupsMap), $editorsOptionsField = new OptionsetField("CanEditType", _t('SiteConfig.EDITHEADER', "Who can edit pages on this site?")), - $editorGroupsField = Object::create('ListboxField', "EditorGroups", _t('SiteTree.EDITORGROUPS', "Editor Groups")) + $editorGroupsField = ListboxField::create("EditorGroups", _t('SiteTree.EDITORGROUPS', "Editor Groups")) ->setMultiple(true)->setSource($groupsMap), $topLevelCreatorsOptionsField = new OptionsetField("CanCreateTopLevelType", _t('SiteConfig.TOPLEVELCREATE', "Who can create pages in the root of the site?")), - $topLevelCreatorsGroupsField = Object::create('ListboxField', "CreateTopLevelGroups", _t('SiteTree.TOPLEVELCREATORGROUPS', "Top level creators")) + $topLevelCreatorsGroupsField = ListboxField::create("CreateTopLevelGroups", _t('SiteTree.TOPLEVELCREATORGROUPS', "Top level creators")) ->setMultiple(true)->setSource($groupsMap) ) ) diff --git a/code/model/SiteTree.php b/code/model/SiteTree.php index cbb98c38..533c8a97 100644 --- a/code/model/SiteTree.php +++ b/code/model/SiteTree.php @@ -1007,9 +1007,6 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid static function prepopulate_permission_cache($permission = 'CanEditType', $ids, $batchCallback = null) { if(!$batchCallback) $batchCallback = "SiteTree::can_{$permission}_multiple"; - //PHP 5.1 requires an array rather than a string for the call_user_func function - $batchCallback=explode('::', $batchCallback); - if(is_callable($batchCallback)) { call_user_func($batchCallback, $ids, Member::currentUserID(), false); } else { @@ -1377,7 +1374,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid if((!$this->URLSegment || $this->URLSegment == 'new-page') && $this->Title) { $this->URLSegment = $this->generateURLSegment($this->Title); } else if($this->isChanged('URLSegment')) { - $filter = Object::create('URLSegmentFilter'); + $filter = URLSegmentFilter::create(); $this->URLSegment = $filter->filter($this->URLSegment); // If after sanitising there is no URLSegment, give it a reasonable default if(!$this->URLSegment) $this->URLSegment = "page-$this->ID"; @@ -1586,7 +1583,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid * @return string Generated url segment */ function generateURLSegment($title){ - $filter = Object::create('URLSegmentFilter'); + $filter = URLSegmentFilter::create(); $t = $filter->filter($title); // Fallback to generic page name if path is empty (= no valid, convertable characters) @@ -1748,7 +1745,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid * * @return FieldList The fields to be displayed in the CMS. */ - function getCMSFields() { + function getCMSFields($params = null) { require_once("forms/Form.php"); // Status / message // Create a status message for multiple parents @@ -1909,13 +1906,13 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid "CanViewType", _t('SiteTree.ACCESSHEADER', "Who can view this page?") ), - $viewerGroupsField = Object::create('ListboxField', "ViewerGroups", _t('SiteTree.VIEWERGROUPS', "Viewer Groups")) + $viewerGroupsField = ListboxField::create("ViewerGroups", _t('SiteTree.VIEWERGROUPS', "Viewer Groups")) ->setMultiple(true)->setSource($groupsMap), $editorsOptionsField = new OptionsetField( "CanEditType", _t('SiteTree.EDITHEADER', "Who can edit this page?") ), - $editorGroupsField = Object::create('ListboxField', "EditorGroups", _t('SiteTree.EDITORGROUPS', "Editor Groups")) + $editorGroupsField = ListboxField::create("EditorGroups", _t('SiteTree.EDITORGROUPS', "Editor Groups")) ->setMultiple(true)->setSource($groupsMap) ) ) @@ -2025,7 +2022,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid * @return FieldList The available actions for this page. */ function getCMSActions() { - $minorActions = Object::create('CompositeField')->setTag('fieldset')->addExtraClass('ss-ui-buttonset'); + $minorActions = CompositeField::create()->setTag('fieldset')->addExtraClass('ss-ui-buttonset'); $actions = new FieldList($minorActions); // "readonly"/viewing version that isn't the current version of the record @@ -2441,6 +2438,36 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid } } + /** + * A flag provides the user with additional data about the current page status, + * for example a "removed from draft" status. Each page can have more than one status flag. + * Returns a map of a unique key to a (localized) title for the flag. + * The unique key can be reused as a CSS class. + * Use the 'updateStatusFlags' extension point to customize the flags. + * Example: "deletedonlive" => "Deleted" + * + * @return array + */ + function getStatusFlags() { + $flags = array(); + if($this->IsDeletedFromStage) { + if($this->ExistsOnLive) { + $flags['removedfromdraft'] = _t('SiteTree.REMOVEDFROMDRAFTSHORT', 'Removed from draft'); + } else { + $flags['deletedonlive'] = _t('SiteTree.DELETEDPAGESHORT', 'Deleted'); + } + } else if($this->IsAddedToStage) { + $flags['addedtodraft'] = _t('SiteTree.ADDEDTODRAFTSHORT', 'New'); + } else if($this->IsModifiedOnStage) { + $flags['modified'] = _t('SiteTree.MODIFIEDONDRAFTSHORT', 'Modified'); + } + + $this->extend('updateStatusFlags', $flags); + + return $flags; + } + + /** * @deprecated 3.0 Use getTreeTitle() */ @@ -2457,29 +2484,27 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid } /** - * TitleWithStatus will return the title in an ,