Created
June 18, 2013 22:23
-
-
Save trentsnippets/5810024 to your computer and use it in GitHub Desktop.
ADD A TAB TO A PAGE: Silverstripe. This code will add a tab to an individual page and allow you to populate it with entries. This gist consists of two different php files.
This file contains hidden or 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 | |
/** Partners.php | |
* Partners Page. | |
* This is all the logic for the Partners page. | |
*/ | |
class PartnersPage extends Page | |
{ | |
//Set relationship | |
public static $has_many = array( | |
'Partners' => 'Partner' | |
); | |
public function getCMSFields() { | |
$fields = parent::getCMSFields(); | |
$gridFieldConfig = GridFieldConfig::create()->addComponents( | |
new GridFieldToolbarHeader(), | |
new GridFieldAddNewButton('toolbar-header-right'), | |
new GridFieldSortableHeader(), | |
new GridFieldDataColumns(), | |
new GridFieldPaginator(20), | |
new GridFieldEditButton(), | |
new GridFieldDeleteAction(), | |
new GridFieldDetailForm() | |
); | |
$gridField = new GridField("Partners", "Some Partners", $this->Partners(), $gridFieldConfig); | |
$fields->addFieldToTab("Root.Partners", $gridField); | |
return $fields; | |
} | |
} | |
/** | |
* Partners Page Controller | |
*/ | |
class PartnersPage_Controller extends Page_Controller | |
{ | |
} | |
?> | |
<?php | |
//Partner.php | |
//This sets the settings for partners to be added to the CMS | |
class Partner extends DataObject | |
{ | |
public static $db = array( | |
'Title' => 'Varchar(255)', | |
'Summary' => 'HTMLText' | |
); | |
public static $has_one = array( | |
'PartnersPage' => 'PartnersPage' | |
); | |
public static $summary_fields = array( | |
'Title' => 'Title', | |
'Summary' => 'Summary' | |
); | |
public function getCMSFields_forPopup(){ | |
return new FieldList( | |
new TextField('Title', 'Title'), | |
new HTMLEditorField('Summary', 'Brief Summary') | |
); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment