Plugins octobercms如何更改我的博客扩展插件上的内容字段小部件类型

Plugins octobercms如何更改我的博客扩展插件上的内容字段小部件类型,plugins,octobercms,Plugins,Octobercms,我需要有博客文章创建,不使用减价小部件的内容输入 我想使用RainLab Blog插件,并理解我不应该更改RainLab\Blog\Post\Models\fields.yml,因为更新将覆盖我的更改 因此,我在上的用户插件扩展教程之后创建了一个扩展,但在我的例子中,我当然扩展了博客插件 在我的插件扩展中,我不需要你在教程中看到的新字段。我所需要做的就是将内容小部件从“markdown”更改为“richeditor”。我已经浏览了这一页,并尝试在我的新机型中使用filterForms。但是我不确

我需要有博客文章创建,不使用减价小部件的内容输入

我想使用RainLab Blog插件,并理解我不应该更改RainLab\Blog\Post\Models\fields.yml,因为更新将覆盖我的更改

因此,我在上的用户插件扩展教程之后创建了一个扩展,但在我的例子中,我当然扩展了博客插件

在我的插件扩展中,我不需要你在教程中看到的新字段。我所需要做的就是将内容小部件从“markdown”更改为“richeditor”。我已经浏览了这一页,并尝试在我的新机型中使用filterForms。但是我不确定,如果那是我应该使用的


任何人都有类似的解决方案问题吗?

你可以像下面的代码一样破解它。只要变量不受
保护
,这将起作用

您需要将
类型
更新为您想要的任何内容(
richeditor
)。您还可以添加/编辑其他属性(
css

为了在表单小部件使用值之前准备这些值,必须钩住before事件。文档化的extend方法钩住after事件,因此更改字段属性为时已晚

class Plugin extends PluginBase
{

    public function register()
    {
        \Event::listen('backend.form.extendFieldsBefore', function ($widget) {
            if ( ! $widget->model instanceof \RainLab\Blog\Models\Post) {
                return;
            }

            array_set($widget->secondaryTabs, 'fields.content.type', 'richeditor');
        });
    }
}

如果您有Rainlab Translate插件,您必须更改一行php代码,因为这行代码覆盖了yaml配置

转到controllers/Posts.php并更改函数:

public function formExtendFieldsBefore($widget)
{
    if (!$model = $widget->model) {
        return;
    }

    if ($model instanceof Post && $model->isClassExtendedWith('RainLab.Translate.Behaviors.TranslatableModel')) {
         $widget->secondaryTabs['fields']['content']['type'] = 'RainLab\Blog\FormWidgets\MLBlogMarkdown';

    }
}
为此

public function formExtendFieldsBefore($widget)
{
    if (!$model = $widget->model) {
        return;
    }

    if ($model instanceof Post && $model->isClassExtendedWith('RainLab.Translate.Behaviors.TranslatableModel')) {
        // $widget->secondaryTabs['fields']['content']['type'] = 'RainLab\Blog\FormWidgets\MLBlogMarkdown';
        $widget->secondaryTabs['fields']['content']['type'] = 'richeditor';
    }
}

这有一个问题,因为这个插件在内部使用降价格式,它被解析为html格式并存储在content\u html列中,但使用richeditor,您已经有了html格式的插件,解析将失败,content\u html将为空,因此您必须在视图中打印content列

好,谢谢。我没有机会再谈这个了。我的自定义插件中已经设置了静态事件侦听方法,但不知道要使用什么逻辑以及要更改哪个数组,因为关于这个的文档不好。我试试看会发生什么。