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

Feature: settings #216

Merged
merged 101 commits into from Aug 5, 2023
Merged

Feature: settings #216

merged 101 commits into from Aug 5, 2023

Conversation

slawkens
Copy link
Owner

@slawkens slawkens commented Feb 8, 2023

This PR adds settings to the admin panel.

Allows to save plugin specific (and general) settings, which can be easily edited in admin panel.

settings.php needs to be declared in plugin.json
"settings": "plugins/example-plugin/settings.php",

Then settings.php can be: (example from password strength plugin)

<?php

return [
	'name' => 'Password Strength',
	'key' => 'password_strength', // will be used with setting() function, must be unique for every setting
	'settings' =>
		[
			[
				'type' => 'section',
				'title' => 'Password Strength'
			],
			'enabled' => [
				'name' => 'Enable Password Strength',
				'type' => 'boolean',
				'desc' => 'Enable Password Strength on Create Account.',
				'default' => true,
			],
			'min_score' => [
				'name' => 'Minimum Score',
				'type' => 'number',
				'min' => 0,
				'max' => 4,
				'desc' => 'Minimum allowed score of password. Value of 0-4.',
				'default' => 4,
				'show_if' => ['enabled', '=', true],
			]
		],
];

Will generate settings like this:
image

Then from any file in your plugin, you can get specified setting, by using the setting('plugin.key') function:

setting('password_strength.enabled')

This will return boolean, either enabled or disabled.

Also fix active link when menu item has subpage
New Settings class
New Plugins::load() method
Move config.php to settings.php
MyAAC Settings will have plugin_name = 'core'
Add compat_config.php
…ings

Categories and sections are now not numbered
Remove example settings plugin
@slawkens
Copy link
Owner Author

slawkens commented Aug 5, 2023

3 years, wow!

But I finally can say its ready 😄

@slawkens slawkens merged commit a72d1a3 into develop Aug 5, 2023
4 checks passed
@slawkens slawkens deleted the feature/settings branch August 5, 2023 19:01
@slawkens slawkens restored the feature/settings branch November 11, 2023 10:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant