Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo

Creating a Holder Page Whose Children are Holders Themselves


Go to End


2 Posts   1666 Views

Avatar
Garrett

Community Member, 245 Posts

8 July 2008 at 7:13am

Hi, I have been builing my site in Silverstripe for the past couple of weeks and have been using the techniques and code I learned in the tutorials, which I completed. Today I have run into the need for something more complex than what the tutorials touched on, and I am sincerely hoping some can give me some guidance on this. I will attempt to describe what I need to do below.

Basically, I have a section of the site called "Capabilities." I have a CapabilitiesHolder.php file which has:

static $allowed_children = array('CapabilityPage');

I have 5 or 6 pages of type CapabilityPage, which I want to be indexed and submenu'ed on the Capabilities front page, which is why I am using $allowed_children. But the problem is that the separate Capability Pages themselves need to use:

ManyManyComplexTableField

...In order for users to be able to add subsections within these pages. Rather than having one big HTMLEditorField on each CapabilityPage, I want users to be able to add Subsection Headings and Text, because this will give them less control over the layout and sttyle on the page.

The issue is that in the tutorials, I was not shown how to use the ManyManyComplexTableField concept WITHIN a page which is a Child of a Holder page. I have a CapabilityPage.php file, and I need to be able to click on each instance of this page type (again, INSIDE CapabilitiesHolder page type), and click on a "Subsections" tab, and then add Headings and Text. I need BOTH a getCMSFields() using ManyManyComplexTableField AND a getCMSFields_forPopup() function. Just don't really know how to use them together. My "Subsections" tab IS shownig up, but there are five empty entries on each page, new entries I add don't seem to be showing up in the database either. I have included a screenshot to show what one of the "Subsections" tabs looks like after rebuilding the database.

I will paste my code from CapabilityPage.php below:

<?php
/**
* Defines the CapabilityPage page type
*/
class CapabilityPage extends Page {

static $many_many = array(
'CapabilitiesEntries' => 'CapabilityPage'
);

static $belongs_many_many = array(
'CapabilitiesEntries' => 'CapabilityEntry'
);

static $db = array(
'CapabilityHeading' => 'Text'
,'CapabilityText' => 'Text'
);

//static $has_one = array(
//'CapabilitiesImage' => 'Image'
//);

function getCMSFields() {
$fields = parent::getCMSFields();

$fields->addFieldToTab('Root.Content.Main', new TextField('Subtitle'), 'Content');

$CapabilitiesSubsection1tablefield = new ManyManyComplexTableField(
$this,
'CapabilitiesEntries',
'CapabilityPage',
array(
'CapabilityHeading' => 'Subsection Heading'
,'CapabilityText' => 'Subsection Text'
//,'CapabilityImage' => 'Subsection Image'
),
'getCMSFields_forPopup'
);
$CapabilitiesSubsection1tablefield->setAddTitle( 'a Subsection' );
$CapabilitiesSubsection1tablefield->setPageSize(100);

$fields->addFieldToTab( 'Root.Content.Subsections', $CapabilitiesSubsection1tablefield );

return $fields;
}

function getCMSFields_forPopup() {

$fields = new FieldSet();

$fields->push(new TextField('CapabilityHeading', 'Subsection Heading'));
$fields->push(new TextField('CapabilityText', 'Subsection Text'));
//$fields->push(new ImageField('CapabilityImage','Subsection Image'));

return $fields;
}

}

class CapabilityPage_Controller extends Page_Controller {

}

?>

Can someone please walk me through this? Seems like a common thing a site builder would have to do.

A sincere thanks in advance,
Garrett

Avatar
Sam

Administrator, 690 Posts

14 July 2008 at 6:15pm

I think that you want to define your getCMSFields_forPopup() method on the CapabilityEntry object instead.