Skip to content

Commit

Permalink
API Deprecate API that's being removed in CMS 6
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Dec 10, 2024
1 parent 57d06fc commit fd919b2
Show file tree
Hide file tree
Showing 10 changed files with 309 additions and 31 deletions.
218 changes: 192 additions & 26 deletions code/Controllers/CMSMain.php

Large diffs are not rendered by default.

18 changes: 16 additions & 2 deletions code/Controllers/CMSPageAddController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
{

Expand All @@ -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
*/
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion code/Controllers/CMSPageSettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
14 changes: 14 additions & 0 deletions code/Controllers/CMSPagesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{

Expand All @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions code/Controllers/CMSSiteTreeFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand Down
29 changes: 27 additions & 2 deletions code/Controllers/LeftAndMainPageIconsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<LeftAndMain>
* @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);
}

/**
Expand All @@ -39,16 +51,29 @@ 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.
*
* @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');
Expand Down
3 changes: 3 additions & 0 deletions code/Model/CurrentPageIdentifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,23 @@

/**
* 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
{

/**
* Get the current page ID.
* @return int
* @deprecated 5.4.0 Will be renamed to currentRecordID()
*/
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);
}
3 changes: 3 additions & 0 deletions code/Model/RedirectorPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class RedirectorPage extends Page

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;
Expand Down
41 changes: 41 additions & 0 deletions code/Model/SiteTree.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,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;

Expand Down Expand Up @@ -327,13 +328,15 @@ 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;

/**
* 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';

Expand Down Expand Up @@ -565,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()
{
Expand Down Expand Up @@ -1022,19 +1026,29 @@ 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;
}

/**
* @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;
}

Expand Down Expand Up @@ -1399,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');
}

Expand Down Expand Up @@ -1801,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) {
Expand Down Expand Up @@ -2844,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);
Expand Down Expand Up @@ -2985,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 '';
}
Expand Down Expand Up @@ -3223,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;
Expand Down Expand Up @@ -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__);
}

Expand Down
3 changes: 3 additions & 0 deletions code/Model/VirtualPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ class VirtualPage extends 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;
Expand Down

0 comments on commit fd919b2

Please sign in to comment.