2012-02-29 14:47:37 +01:00
|
|
|
<?php
|
|
|
|
class GridFieldTestPage extends Page {
|
2012-02-29 16:06:46 +01:00
|
|
|
|
|
|
|
static $has_one = array(
|
|
|
|
"HasOneCompany" => "Company",
|
|
|
|
);
|
|
|
|
|
|
|
|
static $has_many = array(
|
|
|
|
"HasManyCompanies" => "Company",
|
|
|
|
);
|
|
|
|
|
|
|
|
static $many_many = array(
|
|
|
|
"ManyManyCompanies" => "Company",
|
|
|
|
);
|
2012-02-29 14:47:37 +01:00
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
$config = new GridFieldConfig();
|
|
|
|
$config->addComponent(new GridFieldDefaultColumns());
|
|
|
|
$config->addComponent(new GridFieldSortableHeader());
|
|
|
|
$config->addComponent(new GridFieldPaginator);
|
|
|
|
$config->addComponent(new GridFieldFilter());
|
2012-03-08 16:34:14 +01:00
|
|
|
$config->addComponent(new GridFieldDeleteAction());
|
|
|
|
$config->addComponent(new GridFieldEditAction());
|
2012-02-29 14:47:37 +01:00
|
|
|
$config->addComponent($forms = new GridFieldPopupForms());
|
|
|
|
$grid = new GridField('Companies', 'Companies', new DataList('Company'),$config);
|
2012-02-29 16:06:46 +01:00
|
|
|
$fields->addFieldToTab('Root.NoRelation', $grid);
|
2012-02-29 14:47:37 +01:00
|
|
|
|
2012-02-29 16:06:46 +01:00
|
|
|
$config = new GridFieldConfig();
|
|
|
|
$config->addComponent(new GridFieldDefaultColumns());
|
|
|
|
$config->addComponent(new GridFieldSortableHeader());
|
|
|
|
$config->addComponent(new GridFieldPaginator);
|
|
|
|
$config->addComponent(new GridFieldFilter());
|
2012-03-08 16:34:14 +01:00
|
|
|
$config->addComponent(new GridFieldDeleteAction());
|
|
|
|
$config->addComponent(new GridFieldEditAction());
|
2012-02-29 16:06:46 +01:00
|
|
|
$config->addComponent(new GridFieldRelationAdd('Name'));
|
|
|
|
$grid = new GridField('HasManyCompanies', 'HasManyCompanies', new DataList('Company'),$config);
|
|
|
|
$fields->addFieldToTab('Root.HasMany', $grid);
|
|
|
|
|
|
|
|
$config = new GridFieldConfig();
|
|
|
|
$config->addComponent(new GridFieldDefaultColumns());
|
|
|
|
$config->addComponent(new GridFieldSortableHeader());
|
|
|
|
$config->addComponent(new GridFieldPaginator);
|
|
|
|
$config->addComponent(new GridFieldFilter());
|
2012-03-08 16:34:14 +01:00
|
|
|
$config->addComponent(new GridFieldDeleteAction());
|
|
|
|
$config->addComponent(new GridFieldEditAction());
|
2012-02-29 16:06:46 +01:00
|
|
|
$config->addComponent(new GridFieldRelationAdd('Name'));
|
|
|
|
$grid = new GridField('ManyManyCompanies', 'ManyManyCompanies', new DataList('Company'),$config);
|
|
|
|
$fields->addFieldToTab('Root.ManyMany', $grid);
|
2012-02-29 14:47:37 +01:00
|
|
|
|
|
|
|
return $fields;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class GridFieldTestPage_Controller extends Page_Controller {
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $Title = "GridFieldTestPage";
|
|
|
|
|
|
|
|
public function init(){
|
|
|
|
parent::init();
|
|
|
|
Requirements::css('frameworktest/css/gridfieldtest.css','screen');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @return Form
|
|
|
|
*/
|
|
|
|
public function Form(){
|
|
|
|
$config = new GridFieldConfig();
|
|
|
|
$config->addComponent(new GridFieldDefaultColumns());
|
|
|
|
$config->addComponent(new GridFieldSortableHeader());
|
|
|
|
$config->addComponent(new GridFieldPaginator);
|
|
|
|
$config->addComponent(new GridFieldFilter());
|
2012-03-08 16:34:14 +01:00
|
|
|
$config->addComponent(new GridFieldDeleteAction());
|
|
|
|
$config->addComponent(new GridFieldEditAction());
|
2012-02-29 14:47:37 +01:00
|
|
|
$config->addComponent(new GridFieldPopupForms());
|
|
|
|
|
|
|
|
$grid = new GridField('Companies', 'Companies', new DataList('Company'),$config);
|
|
|
|
return new Form($this,'Form',new FieldList($grid),new FieldList());
|
|
|
|
}
|
|
|
|
}
|