I'm using the code from DataObjects as Pages 2, so you can choose one to many categories for each product you created under Product tab in admin.
My question is how can I show the parental pages'(it is called ProductsList.php) titles for the categories? Please see the image for details
Or here is the explain: Because all my Category pages are under one or more parents, and some Categories pages are repeated on the site eg Toyota and Honda. I'd like the parents page's titles to show eg Sale and Rental under the Category check boxes, so that the admin person know which repeated categories to choose.
Here is some related code for the Categories check boxes field:
//Relate to the category pages
static $belongs_many_many = array(
'Categories' => 'CategoryPage'
);
//Categories
$Categories = DataObject::get('CategoryPage');
$fields->addFieldToTab("Root.Categories", new CheckboxsetField('Categories', 'Categories', $Categories));
I'm trying to figure my way through SS, so any help is appreciated.
Thanks a lot.
Sam
Edit/Update:
I managed to make Categories tab to show as Parent-Child eg Sale-Toyota, Sale-Honda, Rental-BMW, Rental-Toyota using the code below. However they are all displayed disorderly/randomly. Any suggestions on how to group them properly eg all the Sales are together and all the Rentals are together?
Code: Add below code to CategoryPage.php
function CheckboxSummary(){
return $this->Parent()->Title . ' - ' . $this->Title;
}
And add $Categories->map('ID', 'CheckboxSummary') to the option for the checkboxset in Product.php
$Categories = DataObject::get('CategoryPage');
$fields->addFieldToTab("Root.Categories", new CheckboxsetField('Categories', 'Categories', $Categories->map('ID', 'CheckboxSummary')));
Thanks:)