Jump to:

7935 Posts in 1536 Topics by 943 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Unpublished many_many relationships on front end.

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 445 Views
  • Shawn Parr
    Avatar
    Community Member
    60 Posts

    Unpublished many_many relationships on front end. Link to this post

    I've run across an odd issue. I've implemented nested DOM on the front end to create a custom data entry system for users we don't want poking around in the full CMS/Model Admin system. It all works great except for one issue.

    We have a page type that also acts as a category system for our DataObjects. A 'CollectionPage' has many_many 'CatalogItems.' 'CatalogItems' belong_many_many 'CollectionPages.' Since 'CollectionPage' extends Page it is versioned and can be either published or non-published. I then use a CheckBoxSetField on the 'CatalogItem' DO so the end user has a tab with a checkbox for each possible 'CollectionPage.'

    Visitors view the 'CollectionPage' and then can see any 'CatalogItems' associated with it, but then an item can be associated to many different 'CollectionPages' (thus like categories).

    If I add a ManyManyDataObjectManager to the fields on the 'CollectionPage' in a new tab to manage the items there it shows any 'CollectionPages' whether they are published or not. Same thing in Model Admin, creating or editing a 'CatalogItem' shows the tab for the 'CollectionPage' selection and shows all of them regardless of their published status.

    However when I view my custom controller that uses DOM on the front-end the tab for 'CollectionPage' selection only shows published 'CollectionPages.' As such users who have permission to add/edit items, but not view the CMS, are unable to associate new items with unpublished collections.

    Any ideas?

  • Shawn Parr
    Avatar
    Community Member
    60 Posts

    Re: Unpublished many_many relationships on front end. Link to this post

    Well, I figured it out.

    Since my 'CollectionPage' extends Page, it is versioned, and versioned automatically grabs the Classname_Live data instead of just Classname when you are viewing the front end, which I knew but didn't know how to get around.

    In my code that gets the pages to put into a CheckboxSetField I had this:

    $collections = DataObject::get('CollectionPage');
    $f->addFieldToTab("Root.Collections", new CheckboxSetField('Collections', 'Collections', $collections));

    To make it work I changed from using DataObject::get() to directly calling Versioned::get_by_stage, which I could then specify to get the draft versions:

    $collections = Versioned::get_by_stage('CollectionPage', 'Draft');
    $f->addFieldToTab("Root.Collections", new CheckboxSetField('Collections', 'Collections', $collections));

    Since part of implementing this 'admin' interface on the front end was to create permissions specific to the app and the editors needed access to view draft pages already this solution works perfectly for me. I haven't tested it but I believe if my users didn't have the ability to view draft pages this solution wouldn't work.

    445 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.