silverstripe 3 changeFieldOrder API使菜单标签消失

时间:2014-11-05 17:46:04

标签: tabs field hidden silverstripe

下午好,

我试图更改CMS显示的DataObject中字段的顺序。在挖掘API之后,我成功地改变了订单。但是,我注意到我的标签已经消失了。

见下面的代码:

class MyDbObj extends DataObject{
   public static $db = array(
        'Title' => 'Varchar',
        'Desc' => 'Text',
        'Weight' => 'Int',
        'Status' => "Enum('Enable, Disable', 'Disable')",
        'Help' => 'HTMLText',
   );

   private static $has_one = array(
        'FileUpload' => 'File'
   );

   private static $has_many = array(
        'Contacts' => 'Contact'
   );


   /**
    * \brief Interesting part here!!!
    *
    * Note: This works great, but it removes my Tabs.
    *
    * Example: This object in the CMS has a default Tab 'Main'
    * The has_many relationship creates another Tab 'Contacts'
    * 
    * Problem: After calling changeFieldOrder, the Tabs are all gone!
    * How to get them back? Thanks.
    */
   public function getCMSFields(){
       $fields = parent::getCMSFields();
       //The next line basically puts FileUpload before the Help (WYISWYG)
       $field_order = array('Title', 'Desc', 'Weight', 'Status', 'FileUpload', 'Help');
       $fields->changeFieldOrder($field_order); //Call to API
       return $fields;
   }
}//class

注意:我甚至使用此处链接中显示的方法实现了整个事情: SilverStripe: changing the order of GridField input elements

我仍然在Tabs消失时遇到同样的问题。

感谢您的协助。

1 个答案:

答案 0 :(得分:3)

如果您在包含$fields->changeFieldOrder($field_order)的{​​{1}}上致电FieldList,它会删除标签。

当您有标签时,您的主要TabSet包含FieldList,其中包含多个TabSet个对象。每个Tab对象都包含自己的Tab

您可以从FieldList标签中获取FieldList,并在此Root.Main上致电changeFieldOrder()

FieldList

或者,您可以手动设置字段,完全控制字段和标签。