diff --git a/code/BatchActions/CMSBatchAction_Archive.php b/code/BatchActions/CMSBatchAction_Archive.php index c0f8412c61..7afd03b457 100644 --- a/code/BatchActions/CMSBatchAction_Archive.php +++ b/code/BatchActions/CMSBatchAction_Archive.php @@ -29,6 +29,6 @@ public function run(SS_List $pages): HTTPResponse public function applicablePages($ids) { // canArchive() is deprecated, not $this->applicablePagesHelper() - return Deprecation::withNoReplacement(fn() => $this->applicablePagesHelper($ids, 'canArchive')); + return Deprecation::withSuppressedNotice(fn() => $this->applicablePagesHelper($ids, 'canArchive')); } } diff --git a/code/BatchActions/CMSBatchAction_Restore.php b/code/BatchActions/CMSBatchAction_Restore.php index d9699c6c59..38a08f680c 100644 --- a/code/BatchActions/CMSBatchAction_Restore.php +++ b/code/BatchActions/CMSBatchAction_Restore.php @@ -20,7 +20,7 @@ class CMSBatchAction_Restore extends CMSBatchAction { public function __construct() { - Deprecation::withNoReplacement(function () { + Deprecation::withSuppressedNotice(function () { Deprecation::notice('5.3.0', 'Will be removed without equivalent functionality to replace it', Deprecation::SCOPE_CLASS); }); } diff --git a/code/Controllers/CMSMain.php b/code/Controllers/CMSMain.php index 4c559bf765..a905fe1e00 100644 --- a/code/Controllers/CMSMain.php +++ b/code/Controllers/CMSMain.php @@ -87,7 +87,13 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr /** * Unique ID for page icons CSS block */ - const PAGE_ICONS_ID = 'PageIcons'; + public const CMS_RECORD_ICONS_ID = 'PageIcons'; + + /** + * Unique ID for page icons CSS block + * @deprecated 5.4.0 use CMS_RECORD_ICONS_ID instead + */ + const PAGE_ICONS_ID = CMSMain::CMS_RECORD_ICONS_ID; private static $url_segment = 'pages'; @@ -103,6 +109,9 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr private static $menu_priority = 10; + /** + * @deprecated 5.4.0 Will be renamed to model_class + */ private static $tree_class = SiteTree::class; private static $session_namespace = CMSMain::class; @@ -140,6 +149,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr 'schema', 'SearchForm', 'SiteTreeAsUL', + 'TreeAsUL', 'getshowdeletedsubtree', 'savetreenode', 'getsubtree', @@ -159,14 +169,17 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr 'TreeIsFiltered' => 'Boolean', 'AddForm' => 'HTMLFragment', 'LinkPages' => 'Text', + 'LinkRecords' => 'Text', 'Link' => 'Text', 'ListViewForm' => 'HTMLFragment', 'ExtraTreeTools' => 'HTMLFragment', 'PageList' => 'HTMLFragment', 'PageListSidebar' => 'HTMLFragment', 'SiteTreeHints' => 'HTMLFragment', + 'TreeHints' => 'HTMLFragment', 'SecurityID' => 'Text', 'SiteTreeAsUL' => 'HTMLFragment', + 'TreeAsUL' => 'HTMLFragment', ]; private static $dependencies = [ @@ -198,7 +211,7 @@ public function index(HTTPRequest $request): HTTPResponse // 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); + $this->setCurrentRecordID(null); } return parent::index($request); @@ -220,9 +233,11 @@ public function getResponseNegotiator(): PjaxResponseNegotiator * Get pages listing area * * @return DBHTMLText + * @deprecated 5.4.0 Will be renamed to RecordList */ public function PageList() { + Deprecation::noticeWithNoReplacment('5.4.0', 'Will be renamed to RecordList'); return $this->renderWith($this->getTemplatesWithSuffix('_PageList')); } @@ -230,9 +245,11 @@ public function PageList() * Page list view for edit-form * * @return DBHTMLText + * @deprecated 5.4.0 Will be removed without equivalent functionality */ public function PageListSidebar() { + Deprecation::noticeWithNoReplacment('5.4.0'); return $this->renderWith($this->getTemplatesWithSuffix('_PageList_Sidebar')); } @@ -257,7 +274,7 @@ public function ShowSwitchView() public function SwitchView($page = null) { if (!$page) { - $page = $this->currentPage(); + $page = $this->currentRecord(); } if ($page) { @@ -290,14 +307,32 @@ public function Link($action = null) return $link; } + /** + * @deprecated 5.4.0 Use LinkRecords instead + */ public function LinkPages() + { + Deprecation::notice('5.4.0', 'Use LinkRecords() instead.'); + return $this->LinkRecords(); + } + + public function LinkRecords() { return CMSPagesController::singleton()->Link(); } + /** + * @deprecated 5.4.0 Use LinkRecordsWithSearch instead + */ public function LinkPagesWithSearch() { - return $this->LinkWithSearch($this->LinkPages()); + Deprecation::notice('5.4.0', 'Use LinkRecordsWithSearch() instead.'); + return $this->LinkRecordsWithSearch(); + } + + public function LinkRecordsWithSearch() + { + return $this->LinkWithSearch($this->LinkRecords()); } /** @@ -376,19 +411,37 @@ public function getCMSEditLinkForManagedDataObject(SiteTree $obj): string return Controller::join_links(CMSPageEditController::singleton()->Link('show'), $obj->ID); } + /** + * @deprecated 5.4.0 Use LinkRecordEdit() instead. + */ public function LinkPageEdit($id = null) + { + Deprecation::notice('5.4.0', 'Use LinkRecordEdit() instead.'); + return $this->LinkRecordEdit($id); + } + + public function LinkRecordEdit($id = null) { if (!$id) { - $id = $this->currentPageID(); + $id = $this->currentRecordID(); } return $this->LinkWithSearch( Controller::join_links(CMSPageEditController::singleton()->Link('show'), $id) ); } + /** + * @deprecated 5.4.0 Use LinkRecordSettings() instead. + */ public function LinkPageSettings() { - if ($id = $this->currentPageID()) { + Deprecation::notice('5.4.0', 'Use LinkRecordSettings() instead.'); + return $this->LinkRecordSettings(); + } + + public function LinkRecordSettings() + { + if ($id = $this->currentRecordID()) { return $this->LinkWithSearch( Controller::join_links(CMSPageSettingsController::singleton()->Link('show'), $id) ); @@ -397,10 +450,19 @@ public function LinkPageSettings() } } + /** + * @deprecated 5.4.0 Use LinkRecordHistory() instead. + */ public function LinkPageHistory() + { + Deprecation::notice('5.4.0', 'Use LinkRecordHistory() instead.'); + return $this->LinkRecordHistory(); + } + + public function LinkRecordHistory() { $controller = Injector::inst()->get(CMSPageHistoryViewerController::class); - if (($id = $this->currentPageID()) && $controller) { + if (($id = $this->currentRecordID()) && $controller) { if ($controller) { return $this->LinkWithSearch( Controller::join_links($controller->Link('show'), $id) @@ -464,7 +526,16 @@ public function LinkWithSearch($link) return $link; } + /** + * @deprecated 5.4.0 Use LinkRecordAdd() instead. + */ public function LinkPageAdd($extra = null, $placeholders = null) + { + Deprecation::notice('5.4.0', 'Use LinkRecordAdd() instead.'); + return $this->LinkRecordAdd($extra, $placeholders); + } + + public function LinkRecordAdd($extra = null, $placeholders = null) { $link = CMSPageAddController::singleton()->Link(); $this->extend('updateLinkPageAdd', $link); @@ -482,10 +553,12 @@ public function LinkPageAdd($extra = null, $placeholders = null) /** * @return string + * @deprecated 5.4.0 Use SilverStripe\CMS\Model\SiteTree::CMSEditLink() instead. */ public function LinkPreview() { - $record = $this->getRecord($this->currentPageID()); + Deprecation::notice('5.4.0', 'Use ' . SiteTree::class . '::CMSEditLink() instead.'); + $record = $this->getRecord($this->currentRecordID()); $baseLink = Director::absoluteBaseURL(); if ($record && $record instanceof SiteTree) { // if we are an external redirector don't show a link @@ -500,8 +573,18 @@ public function LinkPreview() /** * Return the entire site tree as a nested set of ULs + * @deprecated 5.4.0 Use TreeAsUL() instead. */ public function SiteTreeAsUL() + { + Deprecation::notice('5.4.0', 'Use TreeAsUL() instead.'); + return $this->TreeAsUL(); + } + + /** + * Return the entire tree as a nested set of ULs + */ + public function TreeAsUL() { $treeClass = $this->config()->get('tree_class'); $filter = $this->getSearchFilter(); @@ -511,7 +594,7 @@ public function SiteTreeAsUL() 'numChildrenMethod' => $filter ? $filter->getNumChildrenMethod() : 'numChildren', ]); - $html = $this->getSiteTreeFor($treeClass); + $html = $this->getTreeFor($treeClass); $this->extend('updateSiteTreeAsUL', $html); @@ -530,6 +613,7 @@ public function SiteTreeAsUL() * @param callable $filterFunction * @param int $nodeCountThreshold * @return string Nested unordered list with links to each page + * @deprecated 5.4.0 Use getTreeFor() instead. */ public function getSiteTreeFor( $className, @@ -538,6 +622,38 @@ public function getSiteTreeFor( $numChildrenMethod = null, $filterFunction = null, $nodeCountThreshold = null + ) { + Deprecation::notice('5.4.0', 'Use getTreeFor() instead.'); + return $this->getTreeFor( + $className, + $rootID, + $childrenMethod, + $numChildrenMethod, + $filterFunction, + $nodeCountThreshold + ); + } + + /** + * Get a tree HTML listing which displays the nodes under the given criteria. + * + * @param string $className The class of the root object + * @param string $rootID The ID of the root object. If this is null then a complete tree will be + * shown + * @param string $childrenMethod The method to call to get the children of the tree. For example, + * Children, AllChildrenIncludingDeleted, or AllHistoricalChildren + * @param string $numChildrenMethod + * @param callable $filterFunction + * @param int $nodeCountThreshold + * @return string Nested unordered list with links to each record + */ + public function getTreeFor( + $className, + $rootID = null, + $childrenMethod = null, + $numChildrenMethod = null, + $filterFunction = null, + $nodeCountThreshold = null ) { $nodeCountThreshold = is_null($nodeCountThreshold) ? Config::inst()->get($className, 'node_threshold_total') : $nodeCountThreshold; // Provide better defaults from filter @@ -570,7 +686,7 @@ public function getSiteTreeFor( $markingSet->markPartialTree(); // Ensure current page is exposed - $currentPage = $this->currentPage(); + $currentPage = $this->currentRecord(); if ($currentPage) { $markingSet->markToExpose($currentPage); } @@ -655,7 +771,7 @@ public function getTreeNodeClasses(SiteTree $node) */ public function getsubtree(HTTPRequest $request): HTTPResponse { - $html = $this->getSiteTreeFor( + $html = $this->getTreeFor( $this->config()->get('tree_class'), $request->getVar('ID'), null, @@ -751,7 +867,7 @@ public function savetreenode(HTTPRequest $request): HTTPResponse if (!SecurityToken::inst()->checkRequest($request)) { $this->httpError(400); } - if (!$this->CanOrganiseSitetree()) { + if (!$this->canOrganiseTree()) { $this->httpError( 403, _t( @@ -860,12 +976,21 @@ public function savetreenode(HTTPRequest $request): HTTPResponse /** * Whether the current member has the permission to reorganise SiteTree objects. * @return bool + * @deprecated 5.4.0 Use canOrganiseTree instead. */ public function CanOrganiseSitetree() { - return Permission::check('SITETREE_REORGANISE'); + Deprecation::notice('5.4.0', 'Use canOrganiseTree instead.'); + return $this->canOrganiseTree(); } + /** + * Whether the current member has the permission to reorganise SiteTree objects. + */ + public function canOrganiseTree(): bool + { + return Permission::check('SITETREE_REORGANISE'); + } /** * @return boolean @@ -888,9 +1013,11 @@ public function ExtraTreeTools() * and can be modified on extensions through updateSearchContext * * @return \SilverStripe\ORM\Search\SearchContext + * @deprecated 5.4.0 Will be replaced with SilverStripe\CMS\Model\SiteTree::getDefaultSearchContext(). */ public function getSearchContext() { + Deprecation::notice('5.4.0', 'Will be replaced with ' . SiteTree::class . '::getDefaultSearchContext().'); $context = SiteTree::singleton()->getDefaultSearchContext(); $this->extend('updateSearchContext', $context); @@ -960,7 +1087,7 @@ public function getSearchForm() $pageClasses = DropdownField::create( 'Search__ClassName', _t('SilverStripe\\CMS\\Controllers\\CMSMain.PAGETYPEOPT', 'Page type', 'Dropdown for limiting search to a page type'), - $this->getPageTypes() + $this->getRecordTypes() ); $pageClasses->setEmptyString(_t('SilverStripe\\CMS\\Controllers\\CMSMain.PAGETYPEANYOPT', 'Any')); @@ -1004,15 +1131,25 @@ public function getSearchForm() * Returns a sorted array suitable for a dropdown with pagetypes and their translated name * * @return array + * @deprecated 5.4.0 Use getRecordTypes() instead. */ protected function getPageTypes() { - $pageTypes = []; - foreach (SiteTree::page_type_classes() as $pageTypeClass) { - $pageTypes[$pageTypeClass] = SiteTree::singleton($pageTypeClass)->i18n_singular_name(); + Deprecation::notice('5.4.0', 'Use getRecordTypes() instead.'); + return $this->getRecordTypes(); + } + + /** + * Returns a sorted array suitable for a dropdown with record types and their translated name + */ + protected function getRecordTypes(): array + { + $types = []; + foreach (SiteTree::page_type_classes() as $class) { + $types[$class] = SiteTree::singleton($class)->i18n_singular_name(); } - asort($pageTypes); - return $pageTypes; + asort($types); + return $types; } public function doSearch(array $data, Form $form): HTTPResponse @@ -1041,7 +1178,7 @@ public function Breadcrumbs($unlinked = false) { $items = ArrayList::create(); - if (($this->getAction() !== 'index') && ($record = $this->currentPage())) { + if (($this->getAction() !== 'index') && ($record = $this->currentRecord())) { // The page is being edited $this->buildEditFormBreadcrumb($items, $record, $unlinked); } else { @@ -1133,8 +1270,21 @@ private function buildListViewBreadcrumb(ArrayList $items, SiteTree $page): void * 'data-hints' attribute of root node of jsTree. * * @return string Serialized JSON + * @deprecated 5.4.0 Use TreeHints() instead. */ public function SiteTreeHints() + { + Deprecation::notice('5.4.0', 'Use TreeHints() instead.'); + return $this->TreeHints(); + } + + /** + * Create serialized JSON string with site tree hints data to be injected into + * 'data-hints' attribute of root node of jsTree. + * + * @return string Serialized JSON + */ + public function TreeHints(): string { $classes = SiteTree::page_type_classes(); $memberID = Security::getCurrentUser() ? Security::getCurrentUser()->ID : 0; @@ -1206,8 +1356,19 @@ public function SiteTreeHints() * which allows the user to change the page type. * * @return SS_List + * @deprecated 5.4.0 use RecordTypes() instead. */ public function PageTypes() + { + Deprecation::notice('5.4.0', 'Use RecordTypes() instead.'); + return $this->RecordTypes(); + } + + /** + * Populates an array of classes in the CMS + * which allows the user to change the record's ClassName field. + */ + public function RecordTypes(): SS_List { $classes = SiteTree::page_type_classes(); @@ -1311,7 +1472,7 @@ public function EditForm($request = null) $this->httpError(400); return null; } - $this->setCurrentPageID($id); + $this->setCurrentRecordID($id); } return $this->getEditForm(); } @@ -1325,7 +1486,7 @@ public function getEditForm($id = null, $fields = null) { // Get record if (!$id) { - $id = $this->currentPageID(); + $id = $this->currentRecordID(); } $record = $this->getRecord($id); @@ -1571,7 +1732,7 @@ public function ViewState($default = 'treeview') /** * Callback to request the list of page types allowed under a given page instance. - * Provides a slower but more precise response over SiteTreeHints + * Provides a slower but more precise response over TreeHints */ public function childfilter(HTTPRequest $request): HTTPResponse { @@ -1668,7 +1829,7 @@ public function ListViewForm() ->setLinkSpec($linkSpec) ->setAttributes(['data-pjax-target' => 'ListViewForm,Breadcrumbs']) ); - $this->setCurrentPageID($parentID); + $this->setCurrentRecordID($parentID); } $gridField = GridField::create('Page', 'Pages', $list, $gridFieldConfig); $gridField->setAttribute('cms-loading-ignore-url-params', true); @@ -1758,6 +1919,13 @@ public function currentPageID() return $id; } + public function currentRecordID(): ?int + { + $id = parent::currentRecordID(); + $this->extend('updateCurrentPageID', $id); + return $id; + } + //------------------------------------------------------------------------------------------// // Data saving handlers @@ -1891,6 +2059,7 @@ public function getNewItem($id, $setID = true) * * @param Versioned|DataObject $record * @return mixed + * @deprecated 5.4.0 Use SilverStripe\Versioned\RecursivePublishable::publishRecursive() instead. */ public function performPublish($record) { @@ -1998,7 +2167,7 @@ public function archive(array $data, Form $form): HTTPResponse if (!$record || !$record->exists()) { throw new HTTPResponse_Exception("Bad record ID #$id", 404); } - $canArchive = Deprecation::withNoReplacement(fn() => $record->canArchive()); + $canArchive = Deprecation::withSuppressedNotice(fn() => $record->canArchive()); if (!$canArchive) { return Security::permissionFailure(); } @@ -2059,7 +2228,7 @@ public function unpublish(array $data, Form $form): HTTPResponse public function rollback() { return $this->doRollback([ - 'ID' => $this->currentPageID(), + 'ID' => $this->currentRecordID(), 'Version' => $this->getRequest()->param('VersionID') ], null); } @@ -2297,7 +2466,7 @@ protected function getCMSTreeTitle() } /** - * Cache key for SiteTreeHints() method + * Cache key for TreeHints() method * * @param $memberID * @return string diff --git a/code/Controllers/CMSPageAddController.php b/code/Controllers/CMSPageAddController.php index 87a236e85e..8de0237b6c 100644 --- a/code/Controllers/CMSPageAddController.php +++ b/code/Controllers/CMSPageAddController.php @@ -8,6 +8,7 @@ use SilverStripe\Control\HTTPResponse; use SilverStripe\Core\Config\Config; use SilverStripe\Core\Convert; +use SilverStripe\Dev\Deprecation; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\Form; use SilverStripe\Forms\FormAction; @@ -23,6 +24,9 @@ use SilverStripe\Security\Security; use SilverStripe\SiteConfig\SiteConfig; +/** + * @deprecated 5.4.0 Will be replaced with SilverStripe\CMS\Forms\CMSMainAddForm + */ class CMSPageAddController extends CMSPageEditController { @@ -38,6 +42,16 @@ class CMSPageAddController extends CMSPageEditController 'doCancel' ]; + public function __construct() + { + Deprecation::noticeWithNoReplacment( + '5.4.0', + 'Will be replaced with SilverStripe\CMS\Forms\CMSMainAddForm', + Deprecation::SCOPE_CLASS + ); + parent::__construct(); + } + /** * @return Form */ @@ -134,7 +148,7 @@ public function AddForm() $parentModeField->addExtraClass('parent-mode'); - // CMSMain->currentPageID() automatically sets the homepage, + // CMSMain->currentRecordID() automatically sets the homepage, // which we need to counteract in the default selection (which should default to root, ID=0) if ($parentID = $this->getRequest()->getVar('ParentID')) { $parentModeField->setValue('child'); @@ -220,7 +234,7 @@ public function doAdd(array $data, Form $form): HTTPResponse $editController = CMSPageEditController::singleton(); $editController->setRequest($this->getRequest()); - $editController->setCurrentPageID($record->ID); + $editController->setCurrentRecordID($record->ID); $session = $this->getRequest()->getSession(); $session->set( diff --git a/code/Controllers/CMSPageEditController.php b/code/Controllers/CMSPageEditController.php index b15ff27527..7b288445f1 100644 --- a/code/Controllers/CMSPageEditController.php +++ b/code/Controllers/CMSPageEditController.php @@ -13,6 +13,7 @@ use SilverStripe\ORM\ArrayLib; use SilverStripe\ORM\FieldType\DBHTMLText; use SilverStripe\ORM\ValidationResult; +use SilverStripe\Dev\Deprecation; /** * @package cms @@ -53,9 +54,12 @@ public function getClientConfig() /** * Action handler for adding pages to a campaign + * + * @deprecated 5.4.0 Will be removed without equivalent functionality to replace it */ public function addtocampaign(array $data, Form $form): HTTPResponse { + Deprecation::noticeWithNoReplacment('5.4.0'); $id = $data['ID']; $record = \Page::get()->byID($id); @@ -81,9 +85,11 @@ public function addtocampaign(array $data, Form $form): HTTPResponse * * @param HTTPRequest $request * @return Form + * @deprecated 5.4.0 Will be removed without equivalent functionality to replace it */ public function AddToCampaignForm($request) { + Deprecation::noticeWithNoReplacment('5.4.0'); // Get ID either from posted back value, or url parameter $id = $request->param('ID') ?: $request->postVar('ID'); return $this->getAddToCampaignForm($id); @@ -92,9 +98,11 @@ public function AddToCampaignForm($request) /** * @param int $id * @return Form + * @deprecated 5.4.0 Will be removed without equivalent functionality to replace it */ public function getAddToCampaignForm($id) { + Deprecation::noticeWithNoReplacment('5.4.0'); // Get record-specific fields $record = SiteTree::get()->byID($id); diff --git a/code/Controllers/CMSPageSettingsController.php b/code/Controllers/CMSPageSettingsController.php index 1450a33387..340131b6ef 100644 --- a/code/Controllers/CMSPageSettingsController.php +++ b/code/Controllers/CMSPageSettingsController.php @@ -17,7 +17,7 @@ class CMSPageSettingsController extends CMSMain public function getEditForm($id = null, $fields = null) { - $record = $this->getRecord($id ?: $this->currentPageID()); + $record = $this->getRecord($id ?: $this->currentRecordID()); return parent::getEditForm($id, ($record) ? $record->getSettingsFields() : null); } diff --git a/code/Controllers/CMSPagesController.php b/code/Controllers/CMSPagesController.php index 9d30509da6..bc73327969 100644 --- a/code/Controllers/CMSPagesController.php +++ b/code/Controllers/CMSPagesController.php @@ -4,11 +4,15 @@ use SilverStripe\CMS\Model\SiteTree; use SilverStripe\Control\Controller; +use SilverStripe\Dev\Deprecation; use SilverStripe\ORM\ArrayList; use SilverStripe\ORM\DataObject; use SilverStripe\View\ArrayData; use stdClass; +/** + * @deprecated 5.4.0 Will be combined back into SilverStripe\CMS\Controllers\CMSMain + */ class CMSPagesController extends CMSMain { @@ -22,6 +26,16 @@ class CMSPagesController extends CMSMain private static $required_permission_codes = 'CMS_ACCESS_CMSMain'; + public function __construct() + { + Deprecation::noticeWithNoReplacment( + '5.4.0', + 'Will be combined back into ' . CMSMain::class, + Deprecation::SCOPE_CLASS + ); + parent::__construct(); + } + public function LinkPreview() { return false; diff --git a/code/Controllers/CMSSiteTreeFilter.php b/code/Controllers/CMSSiteTreeFilter.php index d73fe96456..8124967ce8 100644 --- a/code/Controllers/CMSSiteTreeFilter.php +++ b/code/Controllers/CMSSiteTreeFilter.php @@ -7,6 +7,7 @@ use SilverStripe\Core\ClassInfo; use SilverStripe\Core\Convert; use SilverStripe\Core\Injector\Injectable; +use SilverStripe\Dev\Deprecation; use SilverStripe\Forms\DateField; use SilverStripe\ORM\DataList; use SilverStripe\ORM\SS_List; @@ -113,8 +114,12 @@ public function getNumChildrenMethod() return $this->numChildrenMethod; } + /** + * @deprecated 5.4.0 Will be renamed to getRecordClasses() + */ public function getPageClasses($page) { + Deprecation::noticeWithNoReplacment('5.4.0', 'Will be renamed to getRecordClasses()'); if ($this->_cache_ids === null) { $this->populateIDs(); } @@ -178,8 +183,12 @@ protected function populateIDs() } } + /** + * @deprecated 5.4.0 Will be renamed to isRecordIncluded() + */ public function isPageIncluded($page) { + Deprecation::noticeWithNoReplacment('5.4.0', 'Will be renamed to isRecordIncluded()'); if ($this->_cache_ids === null) { $this->populateIDs(); } diff --git a/code/Controllers/ContentController.php b/code/Controllers/ContentController.php index 9b93af9976..938591bdc5 100644 --- a/code/Controllers/ContentController.php +++ b/code/Controllers/ContentController.php @@ -297,9 +297,11 @@ public function getMenu($level = 1) /** * @return ArrayList + * @deprecated 5.4.0 Use getMenu() instead. You can continue to use $Menu in templates. */ public function Menu($level) { + Deprecation::noticeWithNoReplacment('5.4.0', 'Use getMenu() instead. You can continue to use $Menu in templates.'); return $this->getMenu($level); } diff --git a/code/Controllers/LeftAndMainPageIconsExtension.php b/code/Controllers/LeftAndMainPageIconsExtension.php index e962322f06..7b639cf936 100644 --- a/code/Controllers/LeftAndMainPageIconsExtension.php +++ b/code/Controllers/LeftAndMainPageIconsExtension.php @@ -13,22 +13,34 @@ use SilverStripe\Core\Extension; use SilverStripe\Core\Flushable; use SilverStripe\Core\Injector\Injector; +use SilverStripe\Dev\Deprecation; use SilverStripe\View\Requirements; /** * Extension to include custom page icons * * @extends Extension + * @deprecated 5.4.0 Will be renamed to SilverStripe\CMS\Controllers\LeftAndMainRecordIconsExtension */ class LeftAndMainPageIconsExtension extends Extension implements Flushable { + public function __construct() + { + Deprecation::noticeWithNoReplacment( + '5.4.0', + 'Will be renamed to SilverStripe\CMS\Controllers\LeftAndMainRecordIconsExtension', + Deprecation::SCOPE_CLASS + ); + parent::__construct(); + } + /** * @throws InvalidArgumentException * @throws ReflectionException */ public function init() { - Requirements::customCSS($this->generatePageIconsCss(), CMSMain::PAGE_ICONS_ID); + Requirements::customCSS($this->generateRecordIconsCss(), CMSMain::CMS_RECORD_ICONS_ID); } /** @@ -39,7 +51,6 @@ public static function flush() Injector::inst()->get(CacheInterface::class . '.SiteTree_PageIcons')->clear(); } - /** * Include CSS for page icons. We're not using the JSTree 'types' option * because it causes too much performance overhead just to add some icons. @@ -47,8 +58,22 @@ public static function flush() * @return string CSS * @throws InvalidArgumentException * @throws ReflectionException + * @deprecated 5.4.0 Use generateRecordIconsCss() instead. */ public function generatePageIconsCss() + { + Deprecation::notice('5.4.0', 'Use generateRecordIconsCss() instead.'); + return $this->generateRecordIconsCss(); + } + + /** + * Include CSS for page icons. We're not using the JSTree 'types' option + * because it causes too much performance overhead just to add some icons. + * + * @throws InvalidArgumentException + * @throws ReflectionException + */ + public function generateRecordIconsCss(): string { /** @var CacheInterface $cache */ $cache = Injector::inst()->get(CacheInterface::class . '.SiteTree_PageIcons'); diff --git a/code/Forms/InternalLinkModalExtension.php b/code/Forms/InternalLinkModalExtension.php index 071c2efb27..f84c902988 100644 --- a/code/Forms/InternalLinkModalExtension.php +++ b/code/Forms/InternalLinkModalExtension.php @@ -5,12 +5,14 @@ use SilverStripe\Admin\LeftAndMainFormRequestHandler; use SilverStripe\Admin\ModalController; use SilverStripe\Core\Extension; +use SilverStripe\Dev\Deprecation; use SilverStripe\Forms\Form; /** * Decorates ModalController with insert internal link * * @extends Extension + * @deprecated 5.4.0 Will be replaced with configuration on SilverStripe\Admin\ModalController */ class InternalLinkModalExtension extends Extension { @@ -23,6 +25,15 @@ class InternalLinkModalExtension extends Extension 'editorAnchorLink', ]; + public function __construct() + { + Deprecation::noticeWithNoReplacment( + '5.4.0', + 'Will be replaced with configuration on ' . ModalController::class, + Deprecation::SCOPE_CLASS + ); + } + /** * Form for inserting internal link pages * diff --git a/code/GraphQL/LinkablePlugin.php b/code/GraphQL/LinkablePlugin.php index 798cb5792d..4f650576b0 100644 --- a/code/GraphQL/LinkablePlugin.php +++ b/code/GraphQL/LinkablePlugin.php @@ -49,7 +49,7 @@ class LinkablePlugin implements ModelQueryPlugin public function __construct() { - Deprecation::withNoReplacement(function () { + Deprecation::withSuppressedNotice(function () { Deprecation::notice('5.3.0', 'Will be moved to the silverstripe/graphql module', Deprecation::SCOPE_CLASS); }); } diff --git a/code/GraphQL/Resolver.php b/code/GraphQL/Resolver.php index 19c4ff5c29..29571b4710 100644 --- a/code/GraphQL/Resolver.php +++ b/code/GraphQL/Resolver.php @@ -13,7 +13,7 @@ class Resolver { public function __construct() { - Deprecation::withNoReplacement(function () { + Deprecation::withSuppressedNotice(function () { Deprecation::notice('5.3.0', 'Will be moved to the silverstripe/graphql module', Deprecation::SCOPE_CLASS); }); } diff --git a/code/Model/CurrentPageIdentifier.php b/code/Model/CurrentPageIdentifier.php index bee76b8239..0228554577 100644 --- a/code/Model/CurrentPageIdentifier.php +++ b/code/Model/CurrentPageIdentifier.php @@ -6,6 +6,7 @@ /** * This interface lets us set up objects that will tell us what the current page is. + * @deprecated 5.4.0 Will be renamed to SilverStripe\CMS\Model\CurrentRecordIdentifier */ interface CurrentPageIdentifier { @@ -13,6 +14,7 @@ interface CurrentPageIdentifier /** * Get the current page ID. * @return int + * @deprecated 5.4.0 Will be renamed to currentRecordID() */ public function currentPageID(); @@ -20,6 +22,7 @@ public function currentPageID(); * Check if the given DataObject is the current page. * @param DataObject $page The page to check. * @return boolean + * @deprecated 5.4.0 Will be renamed to isCurrentRecord() */ public function isCurrentPage(DataObject $page); } diff --git a/code/Model/RedirectorPage.php b/code/Model/RedirectorPage.php index bb4ea2b764..aa0145b4a1 100644 --- a/code/Model/RedirectorPage.php +++ b/code/Model/RedirectorPage.php @@ -23,8 +23,16 @@ */ class RedirectorPage extends Page { + /** + * @deprecated 5.4.0 use class_description instead. + */ private static $description = 'Redirects requests to another location'; + private static string $class_description = 'Redirects requests to another location'; + + /** + * @deprecated 5.4.0 Will be renamed to cms_icon_class + */ private static $icon_class = 'font-icon-p-redirect'; private static $show_stage_link = false; diff --git a/code/Model/SiteTree.php b/code/Model/SiteTree.php index f22296213a..b96a161ea3 100755 --- a/code/Model/SiteTree.php +++ b/code/Model/SiteTree.php @@ -136,6 +136,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi * Used as a cache for `SiteTree::allowedChildren()` * Drastically reduces admin page load when there are a lot of page types * @var array + * @deprecated 5.4.0 will be moved to SilverStripe\ORM\Hierarchy\Hierarchy->cache_allowedChildren */ protected static $_allowedChildren = []; @@ -193,6 +194,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi * * @config * @var array + * @deprecated 5.4.0 Use canCreate() instead. */ private static $need_permission = null; @@ -326,6 +328,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi * @see LeftAndMainPageIconsExtension::generatePageIconsCss() * @config * @var string + * @deprecated 5.4.0 Will be renamed to cms_icon */ private static $icon = null; @@ -333,6 +336,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi * Class attached to page icons in the CMS page tree. Also supports font-icon set. * @config * @var string + * @deprecated 5.4.0 Will be renamed to cms_icon_class */ private static $icon_class = 'font-icon-page'; @@ -419,6 +423,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi * * @config * @var string + * @deprecated 5.4.0 use class_description instead. */ private static $description = null; @@ -431,9 +436,15 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi * * @config * @var string + * @deprecated 5.4.0 use base_class_description instead. */ private static $base_description = 'Generic content page'; + /** + * Description for Page and SiteTree classes, but not inherited by subclasses. + */ + private static string $base_class_description = 'Generic content page'; + /** * @var array */ @@ -557,6 +568,7 @@ public static function get_by_link($link, $cache = true) * Return a subclass map of SiteTree that shouldn't be hidden through {@link SiteTree::$hide_pagetypes} * * @return array + * @deprecated 5.4.0 Will be replaced with updateAllowedSubClasses() */ public static function page_type_classes() { @@ -1014,9 +1026,14 @@ public function getParent() /** * @param CacheInterface $cache * @return $this + * @deprecated 5.4.0 Will be replaced with SilverStripe\CMS\Controllers\CMSMain::setCreatableChildrenCache() */ public function setCreatableChildrenCache(CacheInterface $cache) { + Deprecation::noticeWithNoReplacment( + '5.4.0', + 'Will be replaced with ' . CMSMain::class . '::setCreatableChildrenCache()' + ); $this->creatableChildrenCache = $cache; return $this; @@ -1024,9 +1041,14 @@ public function setCreatableChildrenCache(CacheInterface $cache) /** * @return CacheInterface $cache + * @deprecated 5.4.0 Will be replaced with SilverStripe\CMS\Controllers\CMSMain::getCreatableChildrenCache() */ public function getCreatableChildrenCache() { + Deprecation::noticeWithNoReplacment( + '5.4.0', + 'Will be replaced with ' . CMSMain::class . '::getCreatableChildrenCache()' + ); return $this->creatableChildrenCache; } @@ -1391,9 +1413,11 @@ public function getSiteConfig() /** * @return PermissionChecker + * @deprecated 5.4.0 Will be replaced with a non-static method with the same name. */ public static function getPermissionChecker() { + Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with a non-static method with the same name.'); return Injector::inst()->get(PermissionChecker::class.'.sitetree'); } @@ -1793,9 +1817,14 @@ public function flushCache($persistent = true) * Flushes the member specific cache for creatable children * * @param array $memberIDs + * @deprecated 5.4.0 Will be replaced with SilverStripe\CMS\Controllers\CMSMain::clearCache() */ public function flushMemberCache($memberIDs = null) { + Deprecation::noticeWithNoReplacment( + '5.4.0', + 'Will be replaced with ' . CMSMain::class . '::clearCache()' + ); $cache = SiteTree::singleton()->getCreatableChildrenCache(); if (!$memberIDs) { @@ -2578,7 +2607,7 @@ public function getCMSActions() // If a page is on any stage it can be archived if (($isOnDraft || $isPublished)) { - $canArchive = Deprecation::withNoReplacement(fn() => $this->canArchive()); + $canArchive = Deprecation::withSuppressedNotice(fn() => $this->canArchive()); if ($canArchive) { $title = $isPublished ? _t('SilverStripe\\CMS\\Controllers\\CMSMain.UNPUBLISH_AND_ARCHIVE', 'Unpublish and archive') @@ -2744,8 +2773,6 @@ public function isNew() protected function getClassDropdown() { $classes = SiteTree::page_type_classes(); - $currentClass = null; - $result = []; foreach ($classes as $class) { $instance = singleton($class); @@ -2771,20 +2798,15 @@ protected function getClassDropdown() } } - $pageTypeName = $instance->i18n_singular_name(); - - $currentClass = $class; - $result[$class] = $pageTypeName; + $result[$class] = $instance->i18n_singular_name(); } - // sort alphabetically, and put current on top + // Sort alphabetically, and put current on top asort($result); - if ($currentClass) { - $currentPageTypeName = $result[$currentClass]; - unset($result[$currentClass]); - $result = array_reverse($result ?? []); - $result[$currentClass] = $currentPageTypeName; - $result = array_reverse($result ?? []); + if (isset($result[$this->ClassName])) { + $currentPageTypeName = $result[$this->ClassName]; + unset($result[$this->ClassName]); + $result = [$this->ClassName => $currentPageTypeName] + $result; } return $result; @@ -2843,9 +2865,14 @@ public function allowedChildren() * Gets a list of the page types that can be created under this specific page, including font icons * * @return array + * @deprecated 5.4.0 Will be replaced with SilverStripe\CMS\Controllers\CMSMain::getCreatableSubClasses() */ public function creatableChildPages() { + Deprecation::noticeWithNoReplacment( + '5.4.0', + 'Will be replaced with ' . CMSMain::class . '::getCreatableSubClasses()' + ); // Build the list of candidate children $cache = SiteTree::singleton()->getCreatableChildrenCache(); $cacheKey = $this->generateChildrenCacheKey(Security::getCurrentUser() ? Security::getCurrentUser()->ID : 0); @@ -2984,9 +3011,14 @@ public function getStatusFlags($cached = true) * Returns the CSS class used for the page icon in the site tree. * * @return string + * @deprecated 5.4.0 Will be replaced with SilverStripe\CMS\Controllers\CMSMain::getRecordIconCssClass() */ public function getIconClass() { + Deprecation::noticeWithNoReplacment( + '5.4.0', + 'Will be replaced with ' . CMSMain::class . '::getRecordIconCssClass()' + ); if ($this->config()->get('icon')) { return ''; } @@ -3222,9 +3254,14 @@ public function plural_name() * Generate link to this page's icon * * @return string + * @deprecated 5.4.0 Will be replaced with SilverStripe\CMS\Controllers\CMSMain::getRecordIconUrl() */ public function getPageIconURL() { + Deprecation::noticeWithNoReplacment( + '5.4.0', + 'Will be replaced with ' . CMSMain::class . '::getRecordIconUrl()' + ); $icon = $this->config()->get('icon'); if (!$icon) { return null; @@ -3255,25 +3292,24 @@ public function getPageIconURL() */ public function classDescription() { + // Ensure base class has an appropriate description if not explicitly set, + // since we can't set that config for projects. $base = in_array(static::class, [Page::class, SiteTree::class]); if ($base) { - return $this->config()->get('base_description'); + $baseDescription = static::config()->get('base_class_description'); + // Fall back to the deprecated config + if (!$baseDescription) { + $baseDescription = static::config('base_description'); + } + return $baseDescription; } - return $this->config()->get('description'); - } - - /** - * Get localised description for this page - * - * @return string|null - */ - public function i18n_classDescription() - { - $description = $this->classDescription(); - if ($description) { - return _t(static::class.'.DESCRIPTION', $description); + // For all other classes, use the direct class_description config + $description = parent::classDescription(); + if (!$description) { + // Fall back to the deprecated config + $description = static::config()->get('description'); } - return null; + return $description; } /** @@ -3352,9 +3388,14 @@ protected function updateDependentPages() * * @param int $memberID * @return string + * @deprecated 5.4.0 Will be replaced with SilverStripe\CMS\Controllers\CMSMain::generateChildrenCacheKey() */ protected function generateChildrenCacheKey($memberID) { + Deprecation::noticeWithNoReplacment( + '5.4.0', + 'Will be replaced with ' . CMSMain::class . '::generateChildrenCacheKey()' + ); return md5($memberID . '_' . __CLASS__); } diff --git a/code/Model/SiteTreeExtension.php b/code/Model/SiteTreeExtension.php index 6348a283eb..49a6312268 100644 --- a/code/Model/SiteTreeExtension.php +++ b/code/Model/SiteTreeExtension.php @@ -18,10 +18,10 @@ abstract class SiteTreeExtension extends DataExtension { public function __construct() { - // Wrapping with Deprecation::withNoReplacement() to avoid triggering deprecation notices + // Wrapping with Deprecation::withSuppressedNotice() to avoid triggering deprecation notices // as we are unable to update existing subclasses of this class until a new major // unless we add in the pointless empty methods that are in this class - Deprecation::withNoReplacement(function () { + Deprecation::withSuppressedNotice(function () { $class = Extension::class; Deprecation::notice('5.3.0', "Subclass $class instead", Deprecation::SCOPE_CLASS); }); diff --git a/code/Model/VirtualPage.php b/code/Model/VirtualPage.php index 99bb784fd6..024a83ca51 100644 --- a/code/Model/VirtualPage.php +++ b/code/Model/VirtualPage.php @@ -26,8 +26,16 @@ */ class VirtualPage extends Page { + /** + * @deprecated 5.4.0 use class_description instead. + */ private static $description = 'Displays the content of another page'; + private static string $class_description = 'Displays the content of another page'; + + /** + * @deprecated 5.4.0 Will be renamed to cms_icon_class + */ private static $icon_class = 'font-icon-p-virtual'; public static $virtualFields; diff --git a/composer.json b/composer.json index b274b1073b..3299e698c3 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "php": "^8.1", "silverstripe/admin": "^2.2", "silverstripe/campaign-admin": "^2", - "silverstripe/framework": "^5.2", + "silverstripe/framework": "^5.4", "silverstripe/reports": "^5", "silverstripe/siteconfig": "^5", "silverstripe/versioned": "^2", diff --git a/lang/en.yml b/lang/en.yml index cf415ee713..c4b65ba945 100644 --- a/lang/en.yml +++ b/lang/en.yml @@ -149,6 +149,7 @@ en: HelpChars: ' Special characters are automatically converted or removed.' OK: OK SilverStripe\CMS\Model\RedirectorPage: + CLASS_DESCRIPTION: 'Redirects to an internal page or an external URL' DESCRIPTION: 'Redirects to an internal page or an external URL' FILE: File HEADER: 'This page will redirect users to another page' @@ -188,6 +189,7 @@ en: BUTTONSAVEPUBLISH: Publish BUTTONUNPUBLISH: Unpublish BUTTONUNPUBLISHDESC: 'Remove this page from the published site' + CLASS_DESCRIPTION: 'Generic content page' Comments: Comments Content: Content DEFAULTABOUTCONTENT: '

You can fill this page out with your own content, or delete it and create your own pages.

' @@ -332,6 +334,7 @@ en: many_many_LinkTracking: 'Link tracking' SilverStripe\CMS\Model\VirtualPage: CHOOSE: 'Linked Page' + CLASS_DESCRIPTION: 'Displays the content of another page' DESCRIPTION: 'Displays the content of another page' EditLink: edit HEADER: 'This is a virtual page' diff --git a/tests/php/Model/SiteTreeTest.php b/tests/php/Model/SiteTreeTest.php index 7eb44ec1f2..5bb77b2c31 100644 --- a/tests/php/Model/SiteTreeTest.php +++ b/tests/php/Model/SiteTreeTest.php @@ -1280,7 +1280,7 @@ public function testAllowedChildrenContainsCoreSubclassesButNotHiddenClass() */ public function testAllowedChildren($className, $expected, $assertionMessage) { - $class = new $className; + $class = new $className(); $this->assertEquals($expected, $class->allowedChildren(), $assertionMessage); } @@ -1359,6 +1359,9 @@ public function testAllowedChildrenValidation() ); } + /** + * @return void + */ public function testClassDropdown() { $sitetree = new SiteTree(); @@ -1380,7 +1383,18 @@ public function testClassDropdown() $this->assertArrayNotHasKey(SiteTreeTest_NotRoot::class, $method->invoke($rootPage)); $this->assertArrayHasKey(SiteTreeTest_NotRoot::class, $method->invoke($nonRootPage)); - + foreach ([SiteTreeTest_ClassA::class, SiteTreeTest_ClassB::class] as $className) { + $otherPage = new $className(); + $otherPage->write(); + $result = $method->invoke(object: $otherPage); + $this->assertEquals(array_key_first($result), $className); + // remove the first element as this is not alphabetical + array_shift($result); + // create a sorted array + $resultSorted = $result; + asort($resultSorted); + $this->assertEquals($result, $resultSorted); + } Security::setCurrentUser(null); } diff --git a/yarn.lock b/yarn.lock index dbaf8bd26d..60ab42ea5e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3056,9 +3056,9 @@ create-jest@^29.7.0: prompts "^2.0.1" cross-spawn@^7.0.2, cross-spawn@^7.0.3: - version "7.0.3" - resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6" - integrity sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w== + version "7.0.6" + resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.6.tgz#8a58fe78f00dcd70c370451759dfbfaf03e8ee9f" + integrity sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA== dependencies: path-key "^3.1.0" shebang-command "^2.0.0"