Jump to:

5453 Posts in 1674 Topics by 1198 members

Customising the CMS

SilverStripe Forums » Customising the CMS » adding CheckboxSetField on new Page to CMS - tab does not appear

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

Page: 1
Go to End
Author Topic: 205 Views
  • acktivate
    Avatar
    Community Member
    10 Posts

    adding CheckboxSetField on new Page to CMS - tab does not appear Link to this post

    I am running 3.1.2 and trying to add a group of checkboxes to the CMS. I've added the form to manage the checkboxes to the CMS and that seems to work but I am unable t

    I found an example on the internet from 2011 based on the 2.x framework and can't seem to get it working for 3.x. Feature.php and FeatureAdmin.php seem to work but I can't get the list of checkbox values to appear on a tab in the CMS labeled FeaturePage.php - the tab won't appear.

    suggestions?

    My code is below from mysite/code

    FeaturePage.php
    <?php
    class FeaturePage extends Page {

    // pages can have many features
    static $many_many = array(
    'Features' => 'Feature'
    );

    function getCMSFields() {
    $fields = parent::getCMSFields();
    $features=Feature::get();
    $map = $features->toDropdownMap('ID', 'Name', '(Select one)', true);
           $fields->addFieldToTab('Root.Features', new CheckboxSetField($name = 'Features',$title = 'Select Features',$source = $map));
    }
    }

    class FeaturePage_Controller extends Page_Controller {
    }

    FeatureAdmin.php
    <?php
    class FeatureAdmin extends ModelAdmin {

    private static $managed_models = array(
    'Feature'
    );

    private static $url_segment = 'features';
    private static $menu_title = 'Features';
    }

    Feature.php
    <?php
    class Feature extends DataObject {

    private static $db = array(
    'Name' => 'Varchar(255)',
    'Description' => 'HTMLText'
    );

    public function getCMSFields() {

    $fields = new FieldList();

    $fields->push(new TextField('Name', 'Name of the feature'));
    $fields->push(new TextareaField('Description', 'Short description'));

    return $fields;
    }
    }

  • martimiz
    Avatar
    Forum Moderator
    1038 Posts

    Re: adding CheckboxSetField on new Page to CMS - tab does not appear Link to this post

    Hi,
    Sorry for the late reply, I hope you did already find an answer to your question, but just in case: two things actuallywrong with your code:

    - Your pages getCMSFields didn't return any fields
    - toDropdownMap() doesn't exist in v3.1, use map().

    FeaturePage:

    <?php
    class FeaturePage extends Page {

       // pages can have many features
       private static $many_many = array(
          'Features' => 'Feature'
       );

       public function getCMSFields() {
          $fields = parent::getCMSFields();
       
          $features=Feature::get();
          $map = $features->map('ID', 'Name', '(Select one)', true);
          
          $fields->addFieldToTab(
           'Root.Features',
           new CheckboxSetField($name = 'Features',$title = 'Select Features',$source = $map));
       
          return $fields;
       }
    }

    class FeaturePage_Controller extends Page_Controller {
    }

    Also in Feature I would add the reverse relation, to make it possible to get the pages belonging to a certain feature:

       private static $belongs_many_many = array(
        'FeaturePages' => 'FeaturePage'
       );

    Martine

  • acktivate
    Avatar
    Community Member
    10 Posts

    Re: adding CheckboxSetField on new Page to CMS - tab does not appear Link to this post

    Hi Martine -

    No worries. Your info helped solved the problem but it is not functioning as intended. I fixed the intended functionality by using a Data Extension. It is now working correctly. Thank you.

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