【问题标题】:Silverstripe 4 getCMSFields_forPopup and GridFieldSilverstripe 4 getCMSFields_forPopup 和 GridField
【发布时间】:2020-06-18 01:22:18
【问题描述】:

时隔多年又重新拾起。我不能在 cms 弹出组件中使用 gridfield 吗?在这里,我有成分实体,我想将数据库中的成分添加到食谱实体中。连一个简单的都不会出现。

食谱.php

    ...

    private static $db = [
        'Title' => 'Varchar',
        'Description' => 'Text',
    ];

    private static $has_one = [];

    private static $many_many = [
        'Ingredients' => Ingredient::class,
    ];


    public function getCMSFields_forPopup()
    {
        $gridConfig = GridFieldConfig_RelationEditor::create()->addComponents(
            new GridFieldDeleteAction('unlinkrelation')
        );

        $grid = GridField::create(
            'Ingredients',
            'Ingredients',
            $this->Ingredients(),
            $gridConfig,
        );

        $fields = FieldList::create(
            TextField::create('Title'),
            TextareaField::create('Description'),
            $grid
        );

        // or maybe something like..
        // $fields->addFieldToTab('Main', 'Ingredients', 'Ingredients', $grid);


        return $fields;
    }

【问题讨论】:

    标签: php silverstripe silverstripe-4


    【解决方案1】:

    getCMSFields_forPopup 在 Silverstripe 4 或 Silverstripe 3 中不存在。这是在 Silverstripe 2 中。

    改用getCMSFields

    public function getCMSFields()
    {
        $fields = parent::getCMSFields();
    
        $ingredientsFieldConfig = GridFieldConfig_RelationEditor::create();
    
        $ingredientsField = GridField::create(
            'Ingredients',
            'Ingredients',
            $this->Ingredients(),
            $ingredientsFieldConfig
        );
    
        $fields->addFieldToTab('Root.Main', $ingredientsFieldConfig);
    
        return $fields;
    }
    

    【讨论】:

    • 这解释了它从文档中消失了,新的它必须是明显而简单的,感谢指针芽。
    猜你喜欢
    • 2012-11-03
    • 2021-09-10
    • 1970-01-01
    • 2022-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-05
    相关资源
    最近更新 更多