mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
add controller_name config var to SiteTree for easier override
This commit is contained in:
parent
5735beeb90
commit
1ac1ea73f3
@ -185,6 +185,15 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
|
||||
*/
|
||||
private static $hide_ancestor = null;
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* @config
|
||||
* @var string
|
||||
*/
|
||||
private static $controller_name = null;
|
||||
|
||||
private static $db = array(
|
||||
"URLSegment" => "Varchar(255)",
|
||||
"Title" => "Varchar(255)",
|
||||
@ -2763,11 +2772,16 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
|
||||
|
||||
/**
|
||||
* Find the controller name by our convention of {$ModelClass}Controller
|
||||
* Can be overriden by config variable
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getControllerName()
|
||||
{
|
||||
if ($controller = Config::inst()->get(static::class, 'controller_name')) {
|
||||
return $controller;
|
||||
}
|
||||
|
||||
//default controller for SiteTree objects
|
||||
$controller = ContentController::class;
|
||||
|
||||
|
@ -1504,6 +1504,16 @@ class SiteTreeTest extends SapphireTest
|
||||
$this->assertSame('PageController', $class->getControllerName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that the controller name for a SiteTree instance can be gathered when set directly via config var
|
||||
*/
|
||||
public function testGetControllerNameFromConfig()
|
||||
{
|
||||
Config::inst()->update(Page::class, 'controller_name', 'This\\Is\\A\\New\\Controller');
|
||||
$class = new Page;
|
||||
$this->assertSame('This\\Is\\A\\New\\Controller', $class->getControllerName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that underscored class names (legacy) are still supported (deprecation notice is issued though).
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user