mirror of
https://github.com/silverstripe/silverstripe-frameworktest
synced 2024-10-22 11:06:02 +02:00
NEW Hide test pages from menu, group in common parent
This commit is contained in:
parent
34f0da3d44
commit
a7b2db1e85
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
class GridFieldTestPage extends Page {
|
||||
class GridFieldTestPage extends TestPage {
|
||||
|
||||
static $has_one = array(
|
||||
"HasOneCompany" => "Company",
|
||||
@ -13,21 +13,6 @@ class GridFieldTestPage extends Page {
|
||||
"ManyManyCompanies" => "Company",
|
||||
);
|
||||
|
||||
public function requireDefaultRecords() {
|
||||
parent::requireDefaultRecords();
|
||||
$page = DataObject::get_one('GridFieldTestPage');
|
||||
|
||||
if(!$page) {
|
||||
$page = new GridFieldTestPage();
|
||||
}
|
||||
|
||||
$page->URLSegment = 'gridfieldtest';
|
||||
$page->Title = 'GridField Test';
|
||||
$page->ParentID = 0;
|
||||
$page->write();
|
||||
$page->doPublish();
|
||||
}
|
||||
|
||||
public function getCMSFields() {
|
||||
$fields = parent::getCMSFields();
|
||||
|
||||
@ -36,11 +21,11 @@ class GridFieldTestPage extends Page {
|
||||
$fields->addFieldToTab('Root.NoRelation', $grid);
|
||||
|
||||
$config = new GridFieldConfig_RelationEditor();
|
||||
$grid = new GridField('HasManyCompanies', 'HasManyCompanies', new DataList('Company'),$config);
|
||||
$grid = new GridField('HasManyCompanies', 'HasManyCompanies', $this->HasManyCompanies(),$config);
|
||||
$fields->addFieldToTab('Root.HasMany', $grid);
|
||||
|
||||
$config = new GridFieldConfig_RelationEditor();
|
||||
$grid = new GridField('ManyManyCompanies', 'ManyManyCompanies', new DataList('Company'),$config);
|
||||
$grid = new GridField('ManyManyCompanies', 'ManyManyCompanies', $this->ManyManyCompanies(),$config);
|
||||
$fields->addFieldToTab('Root.ManyMany', $grid);
|
||||
|
||||
return $fields;
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
class LegacyTableFieldsTestPage extends TestPage {
|
||||
|
||||
|
||||
function getCMSFields() {
|
||||
$fields = parent::getCMSFields();
|
||||
|
||||
|
@ -14,6 +14,10 @@ class RelationFieldsTestPage extends TestPage {
|
||||
"ManyManyCompanies" => "Company",
|
||||
"ManyManyPages" => "SiteTree",
|
||||
);
|
||||
|
||||
static $defaults = array(
|
||||
'Title' => 'Relational Fields'
|
||||
);
|
||||
|
||||
function getCMSFields() {
|
||||
$fields = parent::getCMSFields();
|
||||
|
@ -9,7 +9,8 @@ class TestPage extends Page {
|
||||
* We can only create subclasses of TestPage
|
||||
*/
|
||||
function canCreate($member = null) {
|
||||
return $this->class != 'TestPage' && parent::canCreate();
|
||||
// Don't allow creation other than through requireDefaultRecords
|
||||
return false;
|
||||
}
|
||||
|
||||
function requireDefaultRecords(){
|
||||
@ -17,10 +18,28 @@ class TestPage extends Page {
|
||||
|
||||
$class = $this->class;
|
||||
if(!DataObject::get_one($class)) {
|
||||
// Try to create common parent
|
||||
$parent = SiteTree::get()
|
||||
->filter('URLSegment', 'feature-test-pages')
|
||||
->First();
|
||||
|
||||
if(!$parent) {
|
||||
$parent = new Page(array(
|
||||
'Title' => 'Feature Test Pages',
|
||||
'Content' => 'A collection of pages for testing various features in the SilverStripe CMS',
|
||||
'ShowInMenus' => 0
|
||||
));
|
||||
$parent->write();
|
||||
$parent->doPublish();
|
||||
}
|
||||
|
||||
// Create actual page
|
||||
$page = new $class();
|
||||
$page->Title = str_replace("TestPage","",$class) . " Test";
|
||||
$page->Title = str_replace("TestPage","",$class);
|
||||
$page->ShowInMenus = 0;
|
||||
if($parent) $page->ParentID = $parent->ID;
|
||||
$page->write();
|
||||
$page->doPublish();
|
||||
$page->publish('Stage', 'Live');
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user