2016-10-14 03:30:05 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace SilverStripe\Forms\Tests\GridField\GridFieldDetailFormTest;
|
|
|
|
|
|
|
|
use SilverStripe\Dev\TestOnly;
|
|
|
|
use SilverStripe\Forms\GridField\GridField;
|
|
|
|
use SilverStripe\Forms\GridField\GridFieldConfig_RelationEditor;
|
|
|
|
use SilverStripe\Forms\RequiredFields;
|
|
|
|
use SilverStripe\ORM\DataObject;
|
|
|
|
|
|
|
|
class Person extends DataObject implements TestOnly
|
|
|
|
{
|
2016-12-16 05:34:21 +01:00
|
|
|
private static $table_name = 'GridFieldDetailFormTest_Person';
|
2016-10-14 03:30:05 +02:00
|
|
|
|
2020-04-20 19:58:09 +02:00
|
|
|
private static $db = [
|
2016-12-16 05:34:21 +01:00
|
|
|
'FirstName' => 'Varchar',
|
|
|
|
'Surname' => 'Varchar'
|
2020-04-20 19:58:09 +02:00
|
|
|
];
|
2016-10-14 03:30:05 +02:00
|
|
|
|
2020-04-20 19:58:09 +02:00
|
|
|
private static $has_one = [
|
2016-12-16 05:34:21 +01:00
|
|
|
'Group' => PeopleGroup::class
|
2020-04-20 19:58:09 +02:00
|
|
|
];
|
2016-10-14 03:30:05 +02:00
|
|
|
|
2020-04-20 19:58:09 +02:00
|
|
|
private static $many_many = [
|
2016-12-16 05:34:21 +01:00
|
|
|
'Categories' => Category::class,
|
|
|
|
'FavouriteGroups' => PeopleGroup::class
|
2020-04-20 19:58:09 +02:00
|
|
|
];
|
2016-10-14 03:30:05 +02:00
|
|
|
|
2020-04-20 19:58:09 +02:00
|
|
|
private static $many_many_extraFields = [
|
|
|
|
'Categories' => [
|
2016-12-16 05:34:21 +01:00
|
|
|
'IsPublished' => 'Boolean',
|
|
|
|
'PublishedBy' => 'Varchar'
|
2020-04-20 19:58:09 +02:00
|
|
|
]
|
|
|
|
];
|
2016-10-14 03:30:05 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
private static $default_sort = '"FirstName"';
|
2016-10-14 03:30:05 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
public function getCMSFields()
|
|
|
|
{
|
|
|
|
$fields = parent::getCMSFields();
|
|
|
|
// TODO No longer necessary once FormScaffolder uses GridField
|
|
|
|
$fields->replaceField(
|
|
|
|
'Categories',
|
|
|
|
GridField::create(
|
|
|
|
'Categories',
|
|
|
|
'Categories',
|
|
|
|
$this->Categories(),
|
|
|
|
GridFieldConfig_RelationEditor::create()
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$fields->replaceField(
|
|
|
|
'FavouriteGroups',
|
|
|
|
GridField::create(
|
|
|
|
'FavouriteGroups',
|
|
|
|
'Favourite Groups',
|
|
|
|
$this->FavouriteGroups(),
|
|
|
|
GridFieldConfig_RelationEditor::create()
|
|
|
|
)
|
|
|
|
);
|
|
|
|
return $fields;
|
|
|
|
}
|
2016-10-14 03:30:05 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
public function getCMSValidator()
|
|
|
|
{
|
|
|
|
return new RequiredFields(
|
2020-04-20 19:58:09 +02:00
|
|
|
[
|
2016-12-16 05:34:21 +01:00
|
|
|
'FirstName',
|
|
|
|
'Surname'
|
2020-04-20 19:58:09 +02:00
|
|
|
]
|
2016-12-16 05:34:21 +01:00
|
|
|
);
|
|
|
|
}
|
2020-08-27 01:18:54 +02:00
|
|
|
|
|
|
|
public function CMSEditLink()
|
|
|
|
{
|
|
|
|
return sprintf('my-admin/%d', $this->ID);
|
|
|
|
}
|
2016-10-14 03:30:05 +02:00
|
|
|
}
|