Octobercms: How can I make a repeater field jsonable because I am creating this repeater field into a different plugin

点点圈 提交于 2019-12-22 16:36:47

问题


How can I make a repeater field jsonable because I am creating this repeater field into a different plugin and I have created my own plugin. for example: I want to add a repeater field in rainlab.user plugin model but I want to do this by my own plugin so updates on rainlab.user plugin won't affect my work. Thanks


回答1:


You should read about Extending Plugins.

1) First register the events in your custom plugin.php - Example

2) Add the related fields to your migration file - Example - Make sure the field type is set to json or text : $table->json('field_name')->nullable();

Let's say you want to add a Dogs repeater field to the User Model ;

public function boot()
{

    UserModel::extend(function($model)
    {
        $model->addJsonable([
            'dogs',
        ]);
    });

    UsersController::extendFormFields(function($form, $model, $context){

        if (!$model instanceof UserModel) {
            return;
        }

        $form->addTabFields([
            'dogs' => [
                'label'      => 'My Dogs',
                'type'       => 'repeater',
                'form'       => [
                    'fields' => [
                        'breed' => [
                            'label' => 'Breed',
                            'type' => 'dropdown',
                            'options' => [
                                'labrador' => "Labrador",
                                'cocker'   => "Cocker Spaniel"
                            ]
                        ],
                        'name' => [
                            'label' => 'Name',
                            'type' => 'text',
                        ]
                    ],
                ],
            ],
        ]);

    });

}


来源:https://stackoverflow.com/questions/48550277/octobercms-how-can-i-make-a-repeater-field-jsonable-because-i-am-creating-this

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!