Jump to:

5539 Posts in 1738 Topics by 1224 members

Customising the CMS

SilverStripe Forums » Customising the CMS » getCMSFields conditionally showing field in modeladmin

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

Page: 1
Go to End
Author Topic: 628 Views
  • Graphicator
    Community Member
    62 Posts

    getCMSFields conditionally showing field in modeladmin Link to this post

    I was looking a while for the answer to this but couldn't find it.

    I have a DataObject "Testimonial" that is a part of a Page class "BookPage", and I've also added testimonial as a ModelAdmin to list all the testimonials and the books they are under. I used the ModelAdmin to switch Books that the testimonial belongs in, with a "BookPage" dropdown....

       public function getCMSFields(){
          $fields = new FieldList();
          $fields->push( new DropdownField(
           'Please choose a Book',
           $this->getBookSelection() ) );

       function getBookSelection()
        if($Pages = DataObject::get('BookPage'))
           return $Pages->map('ID', 'Title', 'Please Select');
           return array('No Objects found');

    I'd like to be able to show the dropdown menu only when I'm adding or editing a testimonial from the modelAdmin (/admin/testimonial/Testimonial/EditForm/field/Testimonial/item/2/edit) ,
    but not when I'm accessing the testimonial from editing the pages (/admin/pages/edit/EditForm/field/Testimonials/item/new).

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.