Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API Add new SiteTree.hide_pagetypes configuration #2902

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions code/Model/SiteTree.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,20 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
* 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
* of an existing page.
*/
private static array $hide_pagetypes = [];

/**
* You can define the class of the controller that maps to your SiteTree object here if
* you don't want to rely on the magic of appending Controller to the Classname
Expand Down Expand Up @@ -538,7 +547,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_ancestor}
* Return a subclass map of SiteTree that shouldn't be hidden through {@link SiteTree::$hide_pagetypes}
*
* @return array
*/
Expand All @@ -551,7 +560,7 @@ public static function page_type_classes()
unset($classes[$baseClassIndex]);
}

$kill_ancestors = [];
$kill_ancestors = self::config()->get('hide_pagetypes', Config::UNINHERITED) ?? [];
GuySartorelli marked this conversation as resolved.
Show resolved Hide resolved

// figure out if there are any classes we don't want to appear
foreach ($classes as $class) {
Expand Down
12 changes: 12 additions & 0 deletions tests/php/Model/SiteTreeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1209,6 +1209,13 @@ public function testVersionsAreCreated()
$this->assertEquals(3, $p->Version);
}

public function testHidePagetypes()
{
SiteTree::config()->set('hide_pagetypes', ['Page']);
$classes = SiteTree::page_type_classes();
$this->assertNotContains('Page', $classes);
}

public function testPageTypeClasses()
{
$classes = SiteTree::page_type_classes();
Expand All @@ -1223,6 +1230,11 @@ public function testPageTypeClasses()
$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');
$classes = SiteTree::page_type_classes();
$this->assertNotContains('Page', $classes);
GuySartorelli marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down