edalzell/forma 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

edalzell/forma

最新稳定版本:v3.1.2

Composer 安装命令:

composer require edalzell/forma

包简介

Give control panel access to your addon's config

README 文档

README

Latest Version

This package provides an easy way to let users configure your addon.

Requirements

  • PHP 8.2+
  • Laravel 10.0+
  • Statamic 4.0+

Installation

You can install this package via composer using:

composer require edalzell/forma

The package will automatically register itself.

Usage

First, create a config.yaml file in resources\blueprints that contains the blueprint for your configuration. As an example, see Mailchimp's, here.

Then, in the boot method of your addon's Service Provider add:

parent::boot();
\Edalzell\Forma\Forma::add('statamic-rad-pack/mailchimp', ConfigController::class);

The second parameter is optional and only needed if you need custom config handling (see Extending below)

There is a 3rd parameter handle you can use if the config file is NOT the addon's handle.

Once you do that, you get a menu item in the cp that your users can access and use. All data is saved into your addon_handle.php (or $handle as per above) in the config folder.

menu item

Permissions

There is a Manage Addon Settings permission that must be enabled to allow a user to update the settings of any Forma-enabled addons.

Extending

If your addon needs to wangjangle the config before loading and after saving, create your own controller that extends \Edalzell\Forma\ConfigController and use the preProcess and postProcess methods.

For example, the Mailchimp addon stores a config like this:

'user' => [
    'check_consent' => true,
    'consent_field' => 'permission',
    'merge_fields' => [
        [
            'field_name' => 'first_name',
        ],
    ],
    'disable_opt_in' => true,
    'interests_field' => 'interests',
],

But there is no Blueprint that supports that, so it uses a grid, which expects the data to look like:

'user' => [
    [
        'check_consent' => true,
        'consent_field' => 'permission',
        'merge_fields' => [
            [
                'field_name' => 'first_name',
            ],
        ],
        'disable_opt_in' => true,
        'interests_field' => 'interests',
    ]
],

Therefore in its ConfigController:

protected function postProcess(array $values): array
{
    $userConfig = Arr::get($values, 'user');

    return array_merge(
        $values,
        ['user' => $userConfig[0]]
    );
}

protected function preProcess(string $handle): array
{
    $config = config($handle);

    return array_merge(
        $config,
        ['user' => [Arr::get($config, 'user', [])]]
    );
}

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email addon-security@silentz.co instead of using the issue tracker.

License

MIT License

统计信息

  • 总下载量: 67.58k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 10
  • 点击次数: 1
  • 依赖项目数: 10
  • 推荐数: 0

GitHub 信息

  • Stars: 10
  • Watchers: 1
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: mit
  • 更新时间: 2020-11-06