Skip to content

Commit

Permalink
API Remove deprecated API
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Jan 6, 2025
1 parent f62cfe3 commit 8b3ed7a
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 51 deletions.
3 changes: 0 additions & 3 deletions code/Controllers/CMSSiteTreeFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
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\Model\List\SS_List;
Expand Down Expand Up @@ -116,7 +115,6 @@ public function getNumChildrenMethod()

public function getRecordClasses($page)
{
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be renamed to getRecordClasses()');
if ($this->_cache_ids === null) {
$this->populateIDs();
}
Expand Down Expand Up @@ -182,7 +180,6 @@ protected function populateIDs()

public function isRecordIncluded($page)
{
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be renamed to isRecordIncluded()');
if ($this->_cache_ids === null) {
$this->populateIDs();
}
Expand Down
1 change: 0 additions & 1 deletion code/Controllers/ContentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
use SilverStripe\View\Parsers\URLSegmentFilter;
use SilverStripe\View\Requirements;
use SilverStripe\View\SSViewer;
use SilverStripe\Dev\Deprecation;

/**
* The most common kind of controller; effectively a controller linked to a {@link DataObject}.
Expand Down
26 changes: 1 addition & 25 deletions code/Model/SiteTree.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,18 +128,6 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
*/
private static $default_classname = Page::class;

/**
* If you extend a class, and don't want to be able to select the old class
* in the cms, set this to the old class name. Eg, if you extended Product
* to make ImprovedProduct, then you would set $hide_ancestor to Product.
*
* @deprecated 5.2.0 Use hide_pagetypes instead
*
* @config
* @var string
*/
private static $hide_ancestor = null;

/**
* Any fully qualified class names added to this array will be hidden in the CMS
* when selecting page types, e.g. for creating a new page or changing the type
Expand Down Expand Up @@ -485,21 +473,9 @@ public function updateAllowedSubClasses(array &$classes): void
unset($classes[$baseClassIndex]);
}

$kill_ancestors = SiteTree::config()->get('hide_pagetypes', Config::UNINHERITED) ?? [];

// figure out if there are any classes we don't want to appear
foreach ($classes as $class) {
$instance = singleton($class);

// do any of the progeny want to hide an ancestor?
if ($ancestor_to_hide = $instance->config()->get('hide_ancestor')) {
// note for killing later
$kill_ancestors[] = $ancestor_to_hide;
}
}

// If any of the descendents don't want any of the elders to show up, cruelly render the elders surplus to
// requirements
$kill_ancestors = SiteTree::config()->get('hide_pagetypes', Config::UNINHERITED) ?? [];
if ($kill_ancestors) {
$kill_ancestors = array_unique($kill_ancestors);
foreach ($kill_ancestors as $mark) {
Expand Down
27 changes: 5 additions & 22 deletions tests/php/Model/SiteTreeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1181,31 +1181,14 @@ public function testVersionsAreCreated()

public function testHidePagetypes()
{
SiteTree::config()->set('hide_pagetypes', ['Page']);
// Check with default config
$classes = ClassInfo::getValidSubClasses(SiteTree::class);
SiteTree::singleton()->updateAllowedSubClasses($classes);
$this->assertNotContains('Page', $classes);
}
$this->assertNotContains(SiteTree::class, $classes);
$this->assertContains('Page', $classes);

public function testPageTypeClasses()
{
$classes = ClassInfo::getValidSubClasses(SiteTree::class);
SiteTree::singleton()->updateAllowedSubClasses($classes);
$this->assertNotContains(SiteTree::class, $classes, 'Page types do not include base class');
$this->assertContains('Page', $classes, 'Page types do contain subclasses');

// Testing what happens in an incorrect config value is set - hide_ancestor should be a string
Config::modify()->set(SiteTreeTest_ClassA::class, 'hide_ancestor', true);
$newClasses = ClassInfo::getValidSubClasses(SiteTree::class);
SiteTree::singleton()->updateAllowedSubClasses($newClasses);
$this->assertEquals(
$classes,
$newClasses,
'Setting hide_ancestor to a boolean (incorrect) value caused a page class to be hidden'
);

// Testing what happens if a valid config value is set
Config::modify()->set(SiteTreeTest_ClassA::class, 'hide_ancestor', 'Page');
// Confirm specifying to hide the class makes it hidden
SiteTree::config()->set('hide_pagetypes', ['Page']);
$classes = ClassInfo::getValidSubClasses(SiteTree::class);
SiteTree::singleton()->updateAllowedSubClasses($classes);
$this->assertNotContains('Page', $classes);
Expand Down

0 comments on commit 8b3ed7a

Please sign in to comment.