Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make plugin settings consistent with component settings #1989

Closed
brandonkelly opened this issue Sep 16, 2017 · 7 comments
Closed

Make plugin settings consistent with component settings #1989

brandonkelly opened this issue Sep 16, 2017 · 7 comments
Labels
enhancement improvements to existing features extensibility 🔌 features related to plugin/module dev

Comments

@brandonkelly
Copy link
Member

It is weird how everything in Craft 3 that has settings implements the settings as public properties on the model, except for plugins, which must define settings on a separate model.

The reason is because plugins are modules, not models, and currently models are the only thing that support validation.

We could possibly hack something together using Yii’s DynamicModel class, but that would add additional complexity, because setting values, validation rules, and errors would need to be transferred between the plugin and the model when running validation. Ideally Yii 2.1 will implement yiisoft/yii2#11884, and we’ll be able to implement validation support consistently across plugins and other components.

@brandonkelly brandonkelly added the enhancement improvements to existing features label Sep 16, 2017
@brandonkelly brandonkelly added this to the 3.4 milestone Oct 29, 2019
@brandonkelly brandonkelly added the extensibility 🔌 features related to plugin/module dev label Oct 29, 2019
@brandonkelly
Copy link
Member Author

As of Craft 3.4 it will be possible to configure plugins from config/app.php like other application components, via a new craft\services\Plugins::$pluginConfigs property.

return [
    'components' => [
        'plugins' => [
            'pluginConfigs' => [
                'plugin-handle' => [
                    '...' => '...',
                ],
            ],
        ],
    ],
];

Not exactly what I was thinking when I created this issue, but it makes more sense to think of plugins as part of the application than user-definable components like custom fields / widgets / etc.

@piotrpog
Copy link

piotrpog commented Nov 7, 2019

@brandonkelly
Will we be able to still use separate config files to configure plugins as well?

@brandonkelly
Copy link
Member Author

@piotrpog Yeah this just adds another option, for when it makes sense to modify the plugin’s module config directly.

khalwat pushed a commit to nystudio107/craft-instantanalytics that referenced this issue Sep 16, 2022
khalwat pushed a commit to nystudio107/craft-instantanalytics that referenced this issue Sep 16, 2022
@acalvino4
Copy link

Will we be able to still use separate config files to configure plugins as well?

I haven't been able to find any documentation or blogs on how to set this up. I've gotten something working by looking into how other plugins do it, but I'm curious if there is a standard recommended way.

@brandonkelly
Copy link
Member Author

It’s documented here: https://craftcms.com/docs/4.x/extend/plugin-settings.html (see Overriding Setting Values specifically for info on how the config files work).

@acalvino4
Copy link

acalvino4 commented Feb 14, 2023

Should this approach work for non-plugin modules as well?

@brandonkelly
Copy link
Member Author

Modules don’t have a dedicated settings concept. You can make a module configurable by adding public properties to the Module class, and then overriding their values from config/app.php:

return [
    'modules' => [
        'my-module' => [
            'class' => MyModule::class,
            'propertyName' => 'override value',
            // ...
        ],
    ],
    // ...
];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement improvements to existing features extensibility 🔌 features related to plugin/module dev
Projects
None yet
Development

No branches or pull requests

3 participants