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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Relation Modification Editor


Go to End


2 Posts   977 Views

Avatar
Adesso

Community Member, 10 Posts

17 September 2014 at 10:08pm

Edited: 18/09/2014 9:27am

For the setup code, please reffer to Articles that only have relations to Other Pages

When creating a Holding Page and then a Article page it shows the edit form with properties. I would like to show a list of possible relevant Pages that this Article Relates to. I have made a custom Page type called LandingPage and have made several instances of this in the CMS already. What I would like to know is:

How would I give the edit handler a list of Pages to show as check-boxes for this Article so one could set the Relation as you like?

Would the Page type maybe simplify the Query?

I found a topic that resembles my Question, but it does not work in Version 3.1 anymore, and I have no clue how to update it to the current Version.

Greetings from Germany

Avatar
apiening

Community Member, 60 Posts

18 September 2014 at 5:51am

Edited: 18/09/2014 9:28am

Hi Adesso,

not sure if I understand your problem. Do you want to create a ManyMany relationship between pages? Then here is how you do it:

class Article extends Page
{
    private static $many_many = array(
        'RelatedPages' => 'Page',
    );

    public function getCMSFields()
    {
        $fields = parent::getCMSFields();
        $fields->addFieldToTab('Root.Main', GridField::create('RelatedPages', null, Page::get(), GridFieldConfig_RelationEditor::create()));
        return $fields;
    }
}

The GridField is a very powerfull tool but lacks introspection of the relationship beyond the type of the relationship. So you might have to add, configure or remove some of its components in order to get the controls you want.

Cheers

Andy