简体   繁体   English

如何从包创建自定义航海者表单字段?

[英]How can I create a custom voyager Form Field from package?

I'm trying to create a repository composer package to create a custom form field for Voyager, and I found this example: https://github.com/bnku/extended-bread-form-fields , but this it doesn't work for me.我正在尝试创建一个存储库作曲家包来为 Voyager 创建一个自定义表单字段,我发现了这个例子: https : //github.com/bnku/extended-bread-form-fields ,但这不起作用为了我。

So, how do I build a custom field form for Voyager?那么,如何为 Voyager 构建自定义字段表单? The result would be this:结果是这样的:

例子

I tried this repository example.我试过这个存储库示例。

https://github.com/bnku/extended-bread-form-fields (It didn't work for me) https://github.com/bnku/extended-bread-form-fields (它对我不起作用)

and this is my repository test:这是我的存储库测试:

https://github.com/manuel90/crop-image-field https://github.com/manuel90/crop-image-field

This is my composer.json of my package:这是我的包的 composer.json:

{
    "name": "manuel90/crop-image-field",
    "description": "New voyager form field to cut image when uploading",
    "authors": [
        {
            "name": "Manuel",
            "email": "testmlzra@gmail.com"
        }
    ],
    "require": {
        "tcg/voyager": "^1.1"
    },
    "autoload": {
        "psr-4": {
            "Manuel90\\CropImageField\\": "src/"
        }
    },
    "extra": {
        "laravel": {
            "providers": [
                "Manuel90\\CropImageField\\CropImageFieldServiceProvider"
            ]
        }
    }
}

I can see these lines there's a trouble, it didn't detect the class "Voyager", but I don't know how to fix it:我可以看到这些行有问题,它没有检测到“航海者”类,但我不知道如何解决它:


if( class_exists('Voyager') ) {
    Voyager::addFormField(CropImageFormField::class);
}

https://github.com/manuel90/crop-image-field/blob/master/src/CropImageFieldServiceProvider.php#L34-L36 ( According docs this is the way to add a custom form Docs here ) https://github.com/manuel90/crop-image-field/blob/master/src/CropImageFieldServiceProvider.php#L34-L36 (根据文档,这是在此处添加自定义表单文档的方法

I expect to see in the BREAD edit section the new custom field listed on the input type option, like this:我希望在 BREAD 编辑部分看到输入类型选项中列出的新自定义字段,如下所示:

在此处输入图片说明

You need to move the Voyager::addFormField call to the boot() method as this counts as a "piece of functionality" which should be called after the voyager service providers are properly registered.您需要将Voyager::addFormField调用移动到boot()方法,因为这算作“功能块” ,应在正确注册 voyager 服务提供者后调用。

This is missing from Voyager's documentation because they only document the use case for adding FormFields at app level where the call from the register method runs after all vendor Service Providers are registered. Voyager 的文档中没有这一点,因为他们只记录了在应用程序级别添加 FormFields 的用例,其中在注册所有供应商服务提供商后运行来自 register 方法的调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM