feat(plugins): add options to manifest for building forms and storing plugin settings

This commit is contained in:
Yassine Doghri 2024-05-01 18:37:38 +00:00
commit 3d8aedf9c3
8 changed files with 193 additions and 14 deletions

View file

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Modules\Plugins\Controllers;
use CodeIgniter\Exceptions\PageNotFoundException;
use CodeIgniter\HTTP\RedirectResponse;
use Modules\Admin\Controllers\BaseController;
use Modules\Plugins\Plugins;
@ -30,6 +31,43 @@ class PluginsController extends BaseController
]);
}
public function settings(string $pluginKey): string
{
/** @var Plugins $plugins */
$plugins = service('plugins');
$plugin = $plugins->getPlugin($pluginKey);
if ($plugin === null) {
throw PageNotFoundException::forPageNotFound();
}
helper('form');
return view('plugins/settings', [
'plugin' => $plugin,
]);
}
public function settingsAction(string $pluginKey): RedirectResponse
{
/** @var Plugins $plugins */
$plugins = service('plugins');
$plugin = $plugins->getPlugin($pluginKey);
if ($plugin === null) {
throw PageNotFoundException::forPageNotFound();
}
foreach ($plugin->options['settings'] as $option) {
$optionKey = $option['key'];
$optionValue = $this->request->getPost($optionKey);
$plugins->setOption($pluginKey, $optionKey, $optionValue);
}
return redirect()->back();
}
public function activate(string $pluginKey): RedirectResponse
{
service('plugins')->activate($pluginKey);