From 41c19fe845810a65b0e5d1e9944685af95cb5d98 Mon Sep 17 00:00:00 2001 From: Sabina Talipova Date: Tue, 21 May 2024 15:50:01 +1200 Subject: [PATCH] MNT Object for Nested GridField testing --- _config/extensions.yml | 10 +++++ code/fields/NestedGridField/BranchNode.php | 38 +++++++++++++++++++ code/fields/NestedGridField/LeafNode.php | 28 ++++++++++++++ .../NestedGridField/NestedGridFieldAdmin.php | 26 +++++++++++++ code/fields/NestedGridField/RootNode.php | 18 +++++++++ 5 files changed, 120 insertions(+) create mode 100644 code/fields/NestedGridField/BranchNode.php create mode 100644 code/fields/NestedGridField/LeafNode.php create mode 100644 code/fields/NestedGridField/NestedGridFieldAdmin.php create mode 100644 code/fields/NestedGridField/RootNode.php diff --git a/_config/extensions.yml b/_config/extensions.yml index 6f834a6..f4e6d13 100644 --- a/_config/extensions.yml +++ b/_config/extensions.yml @@ -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 diff --git a/code/fields/NestedGridField/BranchNode.php b/code/fields/NestedGridField/BranchNode.php new file mode 100644 index 0000000..983f014 --- /dev/null +++ b/code/fields/NestedGridField/BranchNode.php @@ -0,0 +1,38 @@ + '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; + } +} \ No newline at end of file diff --git a/code/fields/NestedGridField/LeafNode.php b/code/fields/NestedGridField/LeafNode.php new file mode 100644 index 0000000..92f6c27 --- /dev/null +++ b/code/fields/NestedGridField/LeafNode.php @@ -0,0 +1,28 @@ + 'Varchar(50)', + 'Category'=>'Varchar(255)', + ]; + + private static $has_one = [ + 'BranchNode' => BranchNode::class, + ]; + + private static $summary_fields = [ + 'Name', + 'Category', + ]; +} \ No newline at end of file diff --git a/code/fields/NestedGridField/NestedGridFieldAdmin.php b/code/fields/NestedGridField/NestedGridFieldAdmin.php new file mode 100644 index 0000000..0c61aa2 --- /dev/null +++ b/code/fields/NestedGridField/NestedGridFieldAdmin.php @@ -0,0 +1,26 @@ +addComponent(GridFieldNestedForm::create()->setRelationName('BranchNodes')); + return $config; + } +} diff --git a/code/fields/NestedGridField/RootNode.php b/code/fields/NestedGridField/RootNode.php new file mode 100644 index 0000000..6f5ad5f --- /dev/null +++ b/code/fields/NestedGridField/RootNode.php @@ -0,0 +1,18 @@ + 'Varchar(50)', + ]; + + private static $has_many = [ + 'BranchNodes' => BranchNode::class, + ]; +} \ No newline at end of file