Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions

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

ADDING NEW TAB IN CMS


Reply

2 Posts   2719 Views

Avatar
servalman

4 July 2010 at 6:19am (Last edited: 4 July 2010 6:22am), Community Member, 211 Posts

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

Avatar
Willr

4 July 2010 at 11:40am (Last edited: 4 July 2010 11:41am), Forum Moderator, 5511 Posts

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;
}