Last active
December 14, 2015 19:19
-
-
Save priithansen/5135905 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Page.php | |
class Page extends SiteTree { | |
public static $many_many = array( | |
'TestObjects' => 'TestObject' | |
); | |
public static $many_many_extraFields = array( | |
'TestObjects' => array( | |
'ExtraDecimal' => 'Decimal', | |
) | |
); | |
public function getCMSFields() { | |
$fields = parent::getCMSFieldS(); | |
$grid = new GridField( | |
'ExampleGrid', | |
'Example Grid', | |
$this->TestObjects(), | |
GridFieldConfig::create() | |
->addComponent(new GridFieldButtonRow('before')) | |
->addComponent(new GridFieldToolbarHeader()) | |
->addComponent(new GridFieldTitleHeader()) | |
->addComponent(new GridFieldEditableColumns()) | |
->addComponent(new GridFieldDeleteAction()) | |
->addComponent(new GridFieldAddNewInlineButton()) | |
); | |
$fields->addFieldToTab('Root.Main', $grid); | |
return $fields; | |
} | |
} | |
// TestObject.php | |
class TestObject extends DataObject { | |
public static $db = array( | |
'RegularDecimal' => 'Decimal' | |
); | |
public static $belongs_many_many = array( | |
'Pages' => 'Page' | |
); | |
public static $summary_fields = array( | |
'RegularDecimal', 'ExtraDecimal' | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment