Skip to content

Instantly share code, notes, and snippets.

@mooror
Created May 10, 2018 19:48
Show Gist options
  • Save mooror/49c676c58afaa9c5efa271632559d8d2 to your computer and use it in GitHub Desktop.
Save mooror/49c676c58afaa9c5efa271632559d8d2 to your computer and use it in GitHub Desktop.
<?php
/**
* Description
*
* @package silverstripe
* @subpackage mysite
*/
class MealCategory extends DataObject
{
/**
* Database fields
* @var array
*/
private static $db = array(
'Category' => 'Varchar',
'Description' => 'Text',
);
/**
* Belongs_many_many relationship
* @var array
*/
private static $belongs_many_many = array(
'MenuItems' => 'CateringMenuItem',
);
private static $summary_fields = array(
'Category' => 'Category Name',
'DefaultPrice' => 'Default Price',
);
/**
* Changes the default title DBField for all internal Silverstripe functionality
* NOTE: If you have a DataObject with no "Name" or "Title" DBField this MUST be set
*/
function getTitle()
{
return $this->Category;
}
public function getCMSfields() {
$fields = parent::getCMSFields();
// Get the grid that was automatically created for the Many_many relationship
$relationGridfield = $fields->fieldByName("MenuItems");
// Remove the tab that was automatically created for the Gridfield
$fields->removeByName("Root.MenuItems");
// Move the Already existing Gridfield to a different sub-tab
$fields->addFieldToTab('Root.AssignedMenuItems', $relationGridfield);
return $fields;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment