Skip to content

Commit

Permalink
MNT Object for Nested GridField testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Sabina Talipova committed May 22, 2024
1 parent 3b2b4c6 commit 41c19fe
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 0 deletions.
10 changes: 10 additions & 0 deletions _config/extensions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ SilverStripe\FrameworkTest\Model\Employee:
extensions:
- SilverStripe\FrameworkTest\Extension\TestDataObjectExtension

SilverStripe\FrameworkTest\Fields\NestedGridField\RootNode:
extensions:
- SilverStripe\FrameworkTest\Extension\TestDataObjectExtension
SilverStripe\FrameworkTest\Fields\NestedGridField\BranchNode:
extensions:
- SilverStripe\FrameworkTest\Extension\TestDataObjectExtension
SilverStripe\FrameworkTest\Fields\NestedGridField\LeafNode:
extensions:
- SilverStripe\FrameworkTest\Extension\TestDataObjectExtension

SilverStripe\ORM\DatabaseAdmin:
extensions:
- SilverStripe\FrameworkTest\GridFieldArbitraryData\DatabaseBuildExtension
Expand Down
38 changes: 38 additions & 0 deletions code/fields/NestedGridField/BranchNode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace SilverStripe\FrameworkTest\Fields\NestedGridField;

use SilverStripe\Forms\GridField\GridFieldConfig;
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;
use SilverStripe\ORM\DataObject;
use Symbiote\GridFieldExtensions\GridFieldNestedForm;

class BranchNode extends DataObject
{
private static $table_name = 'NestedGridField_BranchNode';

private static $db = [
'Name' => 'Varchar(50)',
'Category' => 'Varchar(50)',
];

private static $has_one = [
'RootNode' => RootNode::class,
];

private static $has_many = [
'LeafNodes' => LeafNode::class,
];

private static $summary_fields = [
'Name',
'Category',
];

public function getNestedConfig(): GridFieldConfig
{
$config = new GridFieldConfig_RecordEditor();
$config->addComponent(GridFieldNestedForm::create()->setRelationName('LeafNodes'));
return $config;
}
}
28 changes: 28 additions & 0 deletions code/fields/NestedGridField/LeafNode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace SilverStripe\FrameworkTest\Fields\NestedGridField;

use SilverStripe\Forms\GridField\GridFieldConfig;
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\Hierarchy\Hierarchy;
use Symbiote\GridFieldExtensions\GridFieldNestedForm;

class LeafNode extends DataObject
{
private static $table_name = 'NestedGridField_LeafNode';

private static $db = [
'Name' => 'Varchar(50)',
'Category'=>'Varchar(255)',
];

private static $has_one = [
'BranchNode' => BranchNode::class,
];

private static $summary_fields = [
'Name',
'Category',
];
}
26 changes: 26 additions & 0 deletions code/fields/NestedGridField/NestedGridFieldAdmin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace SilverStripe\FrameworkTest\Fields\NestedGridField;

use SilverStripe\Admin\ModelAdmin;
use SilverStripe\Forms\GridField\GridFieldConfig;
use SilverStripe\Forms\GridField\GridFieldConfig_RecordViewer;
use Symbiote\GridFieldExtensions\GridFieldNestedForm;

class NestedGridFieldAdmin extends ModelAdmin
{
private static string $url_segment = 'nested-gridfield-section';
private static string $menu_title = 'Nested GridField Section';
private static string $menu_icon_class = 'font-icon-block-banner';

private static array $managed_models = [
RootNode::class,
];

public function getGridFieldConfig(): GridFieldConfig
{
$config = parent::getGridFieldConfig();
$config->addComponent(GridFieldNestedForm::create()->setRelationName('BranchNodes'));
return $config;
}
}
18 changes: 18 additions & 0 deletions code/fields/NestedGridField/RootNode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace SilverStripe\FrameworkTest\Fields\NestedGridField;

use SilverStripe\ORM\DataObject;

class RootNode extends DataObject
{
private static $table_name = 'NestedGridField_RootNode';

private static $db = [
'Name' => 'Varchar(50)',
];

private static $has_many = [
'BranchNodes' => BranchNode::class,
];
}

0 comments on commit 41c19fe

Please sign in to comment.