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



我想在静态页面插件的菜单形式中添加自定义字段"缩略图"。

我已经将此字段添加到project/plugins/rainlab/pages/classes/menuitem/fiields.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

还添加了项目/plugins/rainlab/pages/classes/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 = {
            'title': 1,
            'type': 1,
            'code': 1,
            'thumbnail': 1
        },

但对于文件来说,它不起作用。

我认为你必须扩展插件,更多信息请参阅文档:https://octobercms.com/docs/plugin/extending#extending-后端表单

最新更新