Jump to:

23361 Posts in 18124 Topics by 2862 members

General Questions

SilverStripe Forums » General Questions » ADDING NEW TAB IN CMS

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 2629 Views
  • servalman
    Avatar
    Community Member
    211 Posts

    ADDING NEW TAB IN CMS Link to this post

    Hello

    Here is my problem :

    I have a DataObject (Product) that adds a new product Tab in the backend (that is workin fine) but I also need to add another tab ActifsProduct in the Backend to take advantage of tyne mce wysiwyg and style functions.

    I tried to it following the tutorial and it created some table field.

    What I can't do is adding the tab to the backend codes below (in bold the lines I added to create my new tyni MCE tab:

    if someone could help me it would be great

    Product.php (the DataObject)

    <?
    class Product extends DataObject
    {
       static $db = array (
          'Productname' => 'Text',
          'Imagename' => 'Text',
          'Presentation' => 'Text',
          'Contenance' => 'Text',
          'Actifs' => 'Text',
          'Price' => 'Text'
       );

       static $has_one = array (
          'ProductPage' => 'ProductPage'
       );

       public function getCMSFields_forPopup()
       {
          return new FieldSet(
             new TextField('Productname'),
             new TextField('Imagename'),
             new TextField('Presentation'),
             new TextField('Contenance'),
             new TextField('Actifs'),
             new TextField('Price')
             //new TextareaField('Quote')
             

          );
       }

       public function Link() {
    return $this->ProductPage()->Link("show/$this->ID");
    }

    public function FlashVar() {
    return "myFlashVar=$this->Imagename";
    }

    }

    and ProductPage.php (this where I guess I create new cms tabs)

    <?
    class ProductPage extends SiteTree
    {
       static $has_many = array (
          'Products' => 'Product'
       );

        static $db = array(
       
    'ActifsProduct' => 'HTMLText'
       
    );

       public function getCMSFields()
       {
          $f = parent::getCMSFields();
          $f->addFieldToTab("Root.Content.Products", new DataObjectManager(
             $this,
             'Products',
             'Product',
             array('Productname'=>'Productname','Imagename'=>'Imagename','Presentation' => 'Presentation','Contenance' => 'Contenance','Actifs' => 'Actifs','Price' => 'Price'),
             'getCMSFields_forPopup'
          
          ));
          
          return $f;
       
        $fields = parent::getCMSFields();

    $fields->addFieldToTab('Root.Content.Main', new HtmlEditorField('ActifsProduct'), 'Content');

    return $fields;
       }

    }

       class ProductPage_Controller extends Page_Controller
    {

    public function index() {
    return Director::redirect($this->Products()->First()->Link());
    }

    static $allowed_actions = array (
    'show'
    );
    public function show() {
    return array (
    'Product' => DataObject::get_by_id("Product",$this->urlParams['ID'])

    );
    }
    }

    Thank you

  • Willr
    Avatar
    Forum Moderator
    5483 Posts

    Re: ADDING NEW TAB IN CMS Link to this post

    Your getCMSFields is returning a result before it even gets to your code... and you also don't need to call parent::getCMSFields() twice.

    public function getCMSFields() {
    $f = parent::getCMSFields();
    $f->addFieldToTab("Root.Content.Products", new DataObjectManager(
    $this,
    'Products',
    'Product',
    array('Productname'=>'Productname','Imagename'=>'Imagename','Presentation' => 'Presentation','Contenance' => 'Contenance','Actifs' => 'Actifs','Price' => 'Price'),
    'getCMSFields_forPopup'

    ));

    $f->addFieldToTab('Root.Content.ActifsProduct', new HtmlEditorField('ActifsProduct'));

    return $fields;
    }

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