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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Unpublished many_many relationships on front end.


Reply


2 Posts   555 Views

Avatar
Shawn Parr

Community Member, 60 Posts

18 January 2012 at 8:32am

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?

Avatar
Shawn Parr

Community Member, 60 Posts

19 January 2012 at 11:10am

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.