Skip to content

Instantly share code, notes, and snippets.

@priithansen
Last active December 14, 2015 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save priithansen/5135905 to your computer and use it in GitHub Desktop.
Save priithansen/5135905 to your computer and use it in GitHub Desktop.
<?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