2012-02-29 14:47:37 +01:00
|
|
|
<?php
|
2016-07-01 04:37:50 +02:00
|
|
|
|
|
|
|
use SilverStripe\ORM\DataList;
|
|
|
|
use SilverStripe\FrameworkTest\Model\TestPage;
|
2016-09-07 07:10:55 +02:00
|
|
|
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;
|
|
|
|
use SilverStripe\Forms\GridField\GridField;
|
|
|
|
use SilverStripe\Forms\GridField\GridFieldConfig_RelationEditor;
|
|
|
|
use SilverStripe\View\Requirements;
|
|
|
|
use SilverStripe\Forms\FieldList;
|
|
|
|
use SilverStripe\Forms\Form;
|
|
|
|
|
2015-12-17 21:20:49 +01:00
|
|
|
class GridFieldTestPage extends TestPage
|
|
|
|
{
|
2012-02-29 16:06:46 +01:00
|
|
|
|
2015-12-17 21:20:49 +01:00
|
|
|
private static $has_one = array(
|
2016-07-01 04:37:50 +02:00
|
|
|
"HasOneCompany" => "SilverStripe\\FrameworkTest\\Model\\Company",
|
2015-12-17 21:20:49 +01:00
|
|
|
);
|
2012-02-29 16:06:46 +01:00
|
|
|
|
2015-12-17 21:20:49 +01:00
|
|
|
private static $has_many = array(
|
2016-07-01 04:37:50 +02:00
|
|
|
"HasManyCompanies" => "SilverStripe\\FrameworkTest\\Model\\Company",
|
2015-12-17 21:20:49 +01:00
|
|
|
);
|
2012-02-29 16:06:46 +01:00
|
|
|
|
2015-12-17 21:20:49 +01:00
|
|
|
private static $many_many = array(
|
2016-07-01 04:37:50 +02:00
|
|
|
"ManyManyCompanies" => "SilverStripe\\FrameworkTest\\Model\\Company",
|
2015-12-17 21:20:49 +01:00
|
|
|
);
|
2017-01-15 09:19:56 +01:00
|
|
|
|
2017-07-06 04:25:33 +02:00
|
|
|
private static $owns = [
|
|
|
|
'HasOneCompany',
|
|
|
|
'HasManyCompanies',
|
|
|
|
];
|
|
|
|
|
2015-12-17 21:20:49 +01:00
|
|
|
public function getCMSFields()
|
|
|
|
{
|
|
|
|
$fields = parent::getCMSFields();
|
2012-02-29 14:47:37 +01:00
|
|
|
|
2015-12-17 21:20:49 +01:00
|
|
|
$grids = array();
|
2012-11-30 12:08:46 +01:00
|
|
|
|
2015-12-17 21:20:49 +01:00
|
|
|
$config = new GridFieldConfig_RecordEditor();
|
2016-07-01 04:37:50 +02:00
|
|
|
$grid = new GridField('Companies', 'Companies', new DataList('SilverStripe\\FrameworkTest\\Model\\Company'), $config);
|
2017-07-06 04:25:33 +02:00
|
|
|
$grid->setDescription('Records are NOT owned by the page, and need to be individually published');
|
2015-12-17 21:20:49 +01:00
|
|
|
$fields->addFieldToTab('Root.NoRelation', $grid);
|
|
|
|
$grids[] = $grid;
|
2012-02-29 14:47:37 +01:00
|
|
|
|
2015-12-17 21:20:49 +01:00
|
|
|
$config = new GridFieldConfig_RelationEditor();
|
|
|
|
$grid = new GridField('HasManyCompanies', 'HasManyCompanies', $this->HasManyCompanies(), $config);
|
2017-07-06 04:25:33 +02:00
|
|
|
$grid->setDescription('Records are owned by the page, so should auto-publish');
|
2015-12-17 21:20:49 +01:00
|
|
|
$fields->addFieldToTab('Root.HasMany', $grid);
|
|
|
|
$grids[] = $grid;
|
2012-02-29 16:06:46 +01:00
|
|
|
|
2015-12-17 21:20:49 +01:00
|
|
|
$config = new GridFieldConfig_RelationEditor();
|
|
|
|
$grid = new GridField('ManyManyCompanies', 'ManyManyCompanies', $this->ManyManyCompanies(), $config);
|
2017-07-06 04:25:33 +02:00
|
|
|
$grid->setDescription('Records are NOT owned by the page, and need to be individually published');
|
2015-12-17 21:20:49 +01:00
|
|
|
$fields->addFieldToTab('Root.ManyMany', $grid);
|
|
|
|
$grids[] = $grid;
|
2012-11-30 12:08:46 +01:00
|
|
|
|
2015-12-17 21:20:49 +01:00
|
|
|
return $fields;
|
|
|
|
}
|
2012-02-29 14:47:37 +01:00
|
|
|
}
|
|
|
|
|
2017-01-15 09:19:56 +01:00
|
|
|
class GridFieldTestPage_Controller extends PageController
|
2015-12-17 21:20:49 +01:00
|
|
|
{
|
2014-02-17 22:04:11 +01:00
|
|
|
|
2015-12-17 21:20:49 +01:00
|
|
|
private static $allowed_actions = array(
|
|
|
|
'Form',
|
|
|
|
);
|
2017-01-15 09:19:56 +01:00
|
|
|
|
2015-12-17 21:20:49 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $Title = "GridFieldTestPage";
|
2017-01-15 09:19:56 +01:00
|
|
|
|
2015-12-17 21:20:49 +01:00
|
|
|
public function init()
|
|
|
|
{
|
|
|
|
parent::init();
|
2017-11-06 04:56:59 +01:00
|
|
|
Requirements::css('silverstripe/frameworktest: css/gridfieldtest.css', 'screen');
|
2015-12-17 21:20:49 +01:00
|
|
|
}
|
2017-01-15 09:19:56 +01:00
|
|
|
|
2015-12-17 21:20:49 +01:00
|
|
|
/**
|
|
|
|
*
|
2017-01-15 09:19:56 +01:00
|
|
|
* @return Form
|
2015-12-17 21:20:49 +01:00
|
|
|
*/
|
|
|
|
public function Form()
|
|
|
|
{
|
|
|
|
$config = new GridFieldConfig_RecordEditor();
|
2017-01-15 09:19:56 +01:00
|
|
|
|
2016-07-01 04:37:50 +02:00
|
|
|
$grid = new GridField('Companies', 'Companies', new DataList('SilverStripe\\FrameworkTest\\Model\\Company'), $config);
|
2015-12-17 21:20:49 +01:00
|
|
|
return new Form($this, 'Form', new FieldList($grid), new FieldList());
|
|
|
|
}
|
2012-04-12 05:04:39 +02:00
|
|
|
}
|