Hi All,
I'm working on updating a testimonial page from SS 2.4 to 3.1, I just cant seem to make it display by type.
So far I have the following:
TestimonialPage.php
<?php
class TestimonialPage extends Page {
public static $db = array(
);
public static $has_one = array(
);
public static $has_many = array(
'BigTestimonials' => 'BigTestimonials'
);
function getCMSFields() {
$fields = parent::getCMSFields();
//Testimonials
$gridFieldConfig = GridFieldConfig::create()->addComponents(
new GridFieldToolbarHeader(),
new GridFieldAddNewButton('toolbar-header-right'),
new GridFieldSortableHeader(),
new GridFieldDataColumns(),
new GridFieldPaginator(10),
new GridFieldEditButton(),
new GridFieldDeleteAction(),
new GridFieldDetailForm()
);
$testimonialTable = new GridField("Testimonials", "Testimonials:", $this->BigTestimonials(), $gridFieldConfig);
$fields->addFieldToTab('Root.Testimonials', $testimonialTable);
return $fields;
}
}
class TestimonialPage_Controller extends Page_Controller {
public function GetTestimonials(){
$testimonials = DataObject::Get('BigTestimonials', 'TestimonialPageID = ' . $this->ID);
$testimonials->groupBy('Type');
return $testimonials;
}
}
BigTestimonials.php
<?php
class BigTestimonials extends DataObject{
static $db = array(
'PersonsName' => 'Text',
'Testimonial' => 'HTMLText',
'Type' => 'Varchar(250)'
);
static $has_one = array(
'TestimonialPage' => 'TestimonialPage'
);
public function getCMSFields() {
$fields = new FieldList(new TabSet('Root'));
//General info
$Types = array(
'Parent' => 'Parent',
'School and Tutors' => 'School and Tutors',
'Adult' => 'Adult'
);
$fields->addFieldToTab("Root.Info", new DropdownField('Type', 'Select the testimonial type', $Types));
$fields->addFieldToTab("Root.Info", new TextField('PersonsName', 'Persons name'));
$fields->addFieldToTab("Root.Info", new HTMLEditorField("Testimonial", "Enter the testimonial"));
return $fields;
}
}
TestimonialPage.ss
<div id="contentHolder">
<% include SideBar %>
<div id="content" class="typography">
$Content
<% if BigTestimonials %>
<% loop BigTestimonials.GroupedBy(Type) %>
Type
<div class="testimonialScrollWrap">
<h3>$Type Testimonials</h3>
<div class="testimonialGroupWrap">
<% loop Children %>
<div class="eachtestimonial <% if Last %>last<% end_if %>">
<h5>$PersonsName</h5>
$Testimonial
</div>
<% end_loop%>
</div>
</div>
<hr />
<% end_loop %>
<% end_if %>
</div>
</div>
-helenclarko