如何将自定义字段添加到十月CMS静态页面插件?

问题描述:

我想将自定义字段“缩略图”添加到静态页面插件的菜单表单中。如何将自定义字段添加到十月CMS静态页面插件?

我已经加入这一领域纳入项目/插件/ rainlab /页/班/菜单项/ fields.yaml

# =================================== 
# Field Definitions 
# =================================== 

fields: 

    title: 
     span: left 
     label: rainlab.pages::lang.menuitem.title 

    type: 
     span: right 
     label: rainlab.pages::lang.menuitem.type 
     type: dropdown 

    url: 
     label: rainlab.pages::lang.menuitem.url 

    reference: 
     label: rainlab.pages::lang.menuitem.reference 
     type: dropdown 
     cssClass: input-sidebar-control 

    thumbnail: 
     label: Thumbnail 
     mode: file 
     cssClass: input-sidebar-control 
     type: mediafinder 

// another part of code is default 

另外补充项目/插件/ rainlab /页/班/ MenuItem.php

public $thumbnail; 

public $fillable = [ 
    'title', 
    'nesting', 
    'type', 
    'url', 
    'code', 
    'reference', 
    'cmsPage', 
    'replace', 
    'viewBag', 
    'thumbnail' // new field 
]; 

但它不起作用。如何解决这个问题呢?谢谢。

对于简单的类型的字段也需要改变JS文件

plugins/rainlab/pages/formwidgets/menuitems/assets/js/menu-items-editor.js 

在功能

MenuItemsEditor.prototype.applyMenuItem 

变化basicProperties

例如

basicProperties = { 
      'title': 1, 
      'type': 1, 
      'code': 1, 
      'thumbnail': 1 
     }, 

但文件不起作用。

我认为你必须扩展插件,文档中的更多信息:https://octobercms.com/docs/plugin/extending#extending-backend-form