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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Can I set filter on CMS page before it loads?


Go to End


5 Posts   1836 Views

Avatar
zim

Community Member, 135 Posts

12 November 2009 at 5:38am

I have installed DataObjectManager and am storing Image, title, URL and Category. this resource is available on every page, so amended page.php with necesary code to create BannerResource Tab in CMS.

I am doing this for banners so I am setting the categories to Home, News, CaseStudies.

I would like that when I go to a case studies page in CMS and then click on BannerResources TAB then only the images which have been marked as CaseStudies for category will show up. I can do this once I have entered page as I have a drop down on the resources page created with

$manager->setFilter(
'Category', // The field we're filtering
'Filter by Category', // The label for the filter field
array(
'Home' => 'Home',
'CaseStudies' => 'CaseStudies',
'News' => 'News',
'Portfolio' => 'Portfolio'
) // The dropdown map of values => display text. The values will be matched against the Author field.
);

But I want it to filter on load of page in CMS automatically. Does this make sense?

Can it be doen?

Avatar
Double-A-Ron

Community Member, 607 Posts

15 November 2009 at 9:16pm

Hi Zim,

I don't quite follow you sorry. Mainly because I don't understand your model for this.

Is Banner a DataObject? If so, can you post the code for this and the getCMSFields code for your Page.php?

Aaron

Avatar
UncleCheese

Forum Moderator, 4102 Posts

16 November 2009 at 5:31am

If you're going to force the filter, why use a dropdown filter? Why not just use the filter clause in the DOM constructor?

Avatar
Double-A-Ron

Community Member, 607 Posts

16 November 2009 at 9:42am

Edited: 16/11/2009 9:53am

Hi Zim,

What UC means is there is a filter clause when you create the DOM in your getCMSFields method.

Like this:

// Setup the Options table Dataobject manager
$options = new DataObjectManager(
  $this,
  'Banners',
  'Banner',
  array('Name' => 'Banner Name'),
  'getCMSFields_forPopup',
  "Category = '$this->Category'", // Here is the filter - Get a category from the page, and filter Banners by that Category only
  'SubscriptionTerm ASC'
);
$options->setAddTitle('Pricing Option');   

Or something along those lines. (Sorry for lake of indentation - for the life of me I can't get indents to preseve when I submit posts)

Aaron

Avatar
zim

Community Member, 135 Posts

23 November 2009 at 12:29pm

Thanks for advice.. I had to change my model in the end and do things differently. BUt thanks