Jump to:

3460 Posts in 1064 Topics by 739 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Problem creating TreeMultiselectField to look up Page

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

Page: 1 2
Go to End
Author Topic: 4440 Views
  • Aaron Brockhurst
    Avatar
    Community Member
    30 Posts

    Re: Problem creating TreeMultiselectField to look up Page Link to this post

    Hi Mo

    This is exactly what i am want to achieve and this all works fine for the first page I edit and select the check boxes for. However it's not updating the database table with any other page edits.

    It looks like it's saving the changes made on the first edit of the first page and then not saving any other changes to any other pages

    I get exactly the same results with the code you put.

    Which version of SilverStripe are you using? I'm doing this on 2.3

    Thanks

    Aaron

  • Aaron Brockhurst
    Avatar
    Community Member
    30 Posts

    Re: Problem creating TreeMultiselectField to look up Page Link to this post

    Hooray, I found a solution. It's not the most user friendly if you have lots of content

    I changed the TreeMultiselectField to CheckboxSetField using the following:

    function getCMSFields() {
    $fields = parent::getCMSFields();
    $pageList = DataObject::get('SlimJimsContentPage');
    $fields->addFieldToTab("Root.Content.LinkedPages",new CheckboxSetField('SlimjimsLinkedPages','Select all related pages to appear in the right column', $pageList));
    return $fields;
    }

    And this seems to be updating the database OK. Am still not sure why the TreeMultiselectField wasn't updating the database table for more than one page. If I find an answer I'll update

    Aaron

  • Nobrainer Web
    Avatar
    Community Member
    134 Posts

    Re: Problem creating TreeMultiselectField to look up Page Link to this post

    Hi,

    I have the exact same problem as Aaron - i have used the code from Mo's post.
    I can select and save the checked pages for one page.
    When i go to another page, i do get the dropdown, everything seems to be saved, but it is not, so when i reload the CMS the field of the new page is blank.

    In Page.php i have:

    class Page extends SiteTree {
       
       ...
       
       public static $many_many = array(
          'BotLinksList' => 'Page'
       );
       
       public function getCMSFields() {
          $fields = parent::getCMSFields();
          
          $fields->addFieldToTab('Root.Content.Main', new TextField( 'TitleDescription', "Page Description"));
          $fields->addFieldToTab('Root.Content.Links', new TreeMultiselectField( 'BotLinksList', 'Bottom links', 'SiteTree' ));
          return $fields;
       }
    ...

    My db now has a Page_BotLinksList table, with the fields ID, PageID, SiteTreeID, ChildID

    Any help is appriciated, thx.

  • Juanitou
    Avatar
    Community Member
    323 Posts

    Re: Problem creating TreeMultiselectField to look up Page Link to this post

    It seems there is a bug somewhere in TreeMultiselectField, isn’t it? Has somebody submitted a ticket to Trac? If there’s no bug (and I think it’s probably us that are not understanding how it works), maybe a developer will explain how to use it! ;-)

  • mattclegg
    Avatar
    Community Member
    56 Posts

    Re: Problem creating TreeMultiselectField to look up Page Link to this post

    I'm not sure if this is a bug or not but I'v found that the $many_many 'key' should be the same as the 'class' for a TreeMultiselectField or ManyManyComplexTableField within a Page::getCMSFields().

    For example, this works;

    class ClientType extends Page {
       static $many_many = array(
          'ServiceTree' => 'ServiceTree'
       );
       function getCMSFields() {
           $fields = parent::getCMSFields();
           $fields->addFieldToTab("Root.Content.Main", new TreeMultiselectField("ServiceTree", "Related Services", "ServiceTree"));
    /**
    OR;
       $rcTablefield = new ManyManyComplexTableField(
    $this->owner,
    'ServiceTree',
    'ServiceTree',
    array(
    'Title' => 'ArticleTitle'
    ));
    $rcTablefield->setPermissions(array('show'));
    $rcTablefield->setPageSize('150');
    $fields->addFieldToTab('Root.Content.RelatedContent', $rcTablefield );
    **/
       }
    }
    class ServiceTree extends Page{
    // A class similar BlogTree which gets extended

       static $many_many = array(
          'ClientTypePages' => 'ClientType'
       );
    }

    But it appears to work differently when customising the SiteConfig ie;

    class CustomSiteConfig extends DataObjectDecorator {
       function extraStatics() {
          return array(
             'many_many' => array(
                'FooterLinks' => 'SiteTree'
       );
       }
       public function updateCMSFields(FieldSet &$fields) {
          $fields->addFieldToTab("Root.Main", new CompositeField(
             new TreeMultiselectField("FooterLinks", "Footer Links", "SiteTree")
          ));
    }

    And I think DOM requires that the 'key' be different to the 'class' ?

  • Bureau Berg
    Avatar
    Community Member
    7 Posts

    Re: Problem creating TreeMultiselectField to look up Page Link to this post

    @All, Thanks for sharing.

    @Aaron, Did you got any solution to make this work with TreeMultiselectField custom page list?

    my code is working great with "CheckboxSetField". But not working with TreeMultiselectField in case of custom page list "NewsPage".

    My working Code with "CheckboxSetField":
    ------------------------------------------------------------
    public static $many_many = array(
          "FeaturedArticle"=>"NewsPage",   
       );

    public function getCMSFields() {

          $fields = parent::getCMSFields();
          $pageList = DataObject::get('NewsPage');
          

    $f = parent::getCMSFields();
       $f->addFieldsToTab("Root.Content.FeaturedArticle", array(
    new CheckboxSetField("FeaturedArticle", "Choose a your featured article:", $pageList),
    ));

    return $f;
    }
    ------------------------------------------------------------

    Though when I use "TreeMultiselectField " this with "SiteTree" it works.

    working Code with SiteTree is :

       public static $many_many = array(
          "FeaturedArticle"=>"SiteTree",   
       );

    public function getCMSFields() {

    $f = parent::getCMSFields();
    $f->addFieldsToTab("Root.Content.FeaturedArticle", array(
    new TreeMultiSelectField("FeaturedArticle", "Choose a your featured article:", "SiteTree"),
    ));
       
    }

    Any idea why it is not working with "NewsPage" class in TreeMultiselectField ?

    4440 Views
Page: 1 2
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.