Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Can I set filter on CMS page before it loads?

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: 1250 Views
  • zim
    Avatar
    Community Member
    135 Posts

    Can I set filter on CMS page before it loads? Link to this post

    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?

  • Double-A-Ron
    Avatar
    Community Member
    599 Posts

    Re: Can I set filter on CMS page before it loads? Link to this post

    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

  • UncleCheese
    Avatar
    4085 Posts

    Re: Can I set filter on CMS page before it loads? Link to this post

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

  • Double-A-Ron
    Avatar
    Community Member
    599 Posts

    Re: Can I set filter on CMS page before it loads? Link to this post

    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

  • zim
    Avatar
    Community Member
    135 Posts

    Re: Can I set filter on CMS page before it loads? Link to this post

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

    1250 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.