diff --git a/Config/service.json b/Config/service.json
index 11b41cb..2596a2a 100644
--- a/Config/service.json
+++ b/Config/service.json
@@ -5,15 +5,28 @@
"@query"
]
},
- "starterkit.hook": {
- "class": "Starterkit\\Services\\StarterkitHook",
+ "starterkit.hook.config": {
+ "class": "Starterkit\\Services\\HookConfig",
"arguments": [
- "@query",
- "@schema"
+ "@config"
],
"hooks": {
+ "config.edit.menu": "menu",
+ "config.edit.starterkit.form.generate": "form",
+ "config.update.starterkit.validator": "validator",
+ "config.update.starterkit.before": "before"
}
- },
+ },
+ "starterkit.hook.user": {
+ "class": "Starterkit\\Services\\HookUser",
+ "hooks": {
+ "user.permission.module": "hookPermission",
+ "route.starterkit.created": "hookStarterkitCreated",
+ "route.starterkit.store": "hookStarterkitCreate",
+ "route.starterkit.edit": "hookStarterkitEdited",
+ "route.starterkit.update": "hookStarterkitEdited"
+ }
+ },
"starterkit.install": {
"class": "Starterkit\\Install",
"hooks": {
diff --git a/Controller/Starterkit.php b/Controller/Starterkit.php
index ee80b94..a386946 100644
--- a/Controller/Starterkit.php
+++ b/Controller/Starterkit.php
@@ -26,7 +26,6 @@ public function index($req)
$linkShow = self::router()->getRoute('starterkit.show', [ ':id' => 1 ]);
return self::template()
- ->setTheme(false)
->view('page', [
'title_main' => 'Starterkit index'
])
@@ -44,7 +43,7 @@ public function admin($req)
$linkEdit = self::router()->getRoute('starterkit.edit', [ ':id' => 1 ]);
return self::template()
- ->setTheme()
+ ->getTheme('theme_admin')
->view('page', [
'title_main' => 'Starterkit admin',
])
@@ -60,7 +59,6 @@ public function admin($req)
public function show($id, $req)
{
return self::template()
- ->setTheme(false)
->view('page', [
'title_main' => 'Starterkit content ' . $id,
])
@@ -91,7 +89,7 @@ public function create($req)
->submit('submit', 'Enregistrer', [ 'class' => 'btn btn-success' ]);
return self::template()
- ->setTheme()
+ ->getTheme('theme_admin')
->view('page', [
'title_main' => 'Starterkit create'
])
@@ -133,7 +131,7 @@ public function edit($id, $req)
->submit('submit', 'Enregistrer', [ 'class' => 'btn btn-success' ]);
return self::template()
- ->setTheme()
+ ->getTheme('theme_admin')
->view('page', [
'title_main' => 'Starterkit edit ' . $id
])
diff --git a/Install.php b/Install.php
index bb40cd9..9269e01 100644
--- a/Install.php
+++ b/Install.php
@@ -23,6 +23,8 @@ public function install($container)
->values([ 'value_1', null ])
->execute();
// */
+ $container->config()->set('settings.start_check', '');
+ $container->config()->set('settings.start_text', '');
}
public function hookInstall($container)
@@ -34,36 +36,20 @@ public function hookInstall($container)
public function hookInstallUser($container)
{
if ($container->schema()->hasTable('user')) {
- $container->query()->insertInto('permission', [
- 'permission_id',
- 'permission_label'
- ])
- ->values([ 'starterkit.index', 'Voir starterkit' ])
- ->values([ 'starterkit.admin', 'Voir l\'administration' ])
- ->values([ 'starterkit.show', 'Voir le contenu' ])
- ->values([ 'starterkit.create', 'Voir le formulaire d\'ajout' ])
- ->values([ 'starterkit.store', 'Ajouter' ])
- ->values([ 'starterkit.edit', 'Voir le formulaire d\'édition' ])
- ->values([ 'starterkit.update', 'Éditer' ])
- ->values([ 'starterkit.delete', 'Supprimer' ])
- ->execute();
-
$container->query()->insertInto('role_permission', [
'role_id',
'permission_id'
])
- ->values([ 1, 'starterkit.index' ])
- ->values([ 2, 'starterkit.index' ])
->values([ 3, 'starterkit.index' ])
->values([ 3, 'starterkit.admin' ])
- ->values([ 1, 'starterkit.show' ])
- ->values([ 2, 'starterkit.show' ])
->values([ 3, 'starterkit.show' ])
- ->values([ 3, 'starterkit.create' ])
- ->values([ 3, 'starterkit.store' ])
- ->values([ 3, 'starterkit.edit' ])
- ->values([ 3, 'starterkit.update' ])
+ ->values([ 3, 'starterkit.created' ])
+ ->values([ 3, 'starterkit.edited' ])
->values([ 3, 'starterkit.delete' ])
+ ->values([ 2, 'starterkit.index' ])
+ ->values([ 2, 'starterkit.show' ])
+ ->values([ 1, 'starterkit.index' ])
+ ->values([ 1, 'starterkit.show' ])
->execute();
}
}
@@ -71,10 +57,11 @@ public function hookInstallUser($container)
public function hookInstallMenu($container)
{
if ($container->schema()->hasTable('menu')) {
- $container->query()->insertInto('menu_link', [ 'title_link', 'link',
+ $container->query()->insertInto('menu_link', [ 'key', 'title_link', 'link',
'menu', 'weight', 'parent' ])
->values([
- ' Starterkit',
+ 'starterkit.admin',
+ ' Starterkit',
'admin/starterkit',
'admin-menu',
50,
@@ -82,9 +69,10 @@ public function hookInstallMenu($container)
])
->execute();
- $container->query()->insertInto('menu_link', [ 'title_link', 'link',
+ $container->query()->insertInto('menu_link', [ 'key', 'title_link', 'link',
'menu', 'weight', 'parent' ])
->values([
+ 'starterkit.index',
'Starterkit',
'starterkit/index',
'main-menu',
@@ -98,12 +86,6 @@ public function hookInstallMenu($container)
public function uninstall($container)
{
if ($container->schema()->hasTable('user')) {
- $container->query()
- ->from('permission')
- ->delete()
- ->where('permission_id', 'like', 'starterkit%')
- ->execute();
-
$container->query()
->from('role_permission')
->delete()
diff --git a/Services/HookConfig.php b/Services/HookConfig.php
new file mode 100644
index 0000000..cd5a80a
--- /dev/null
+++ b/Services/HookConfig.php
@@ -0,0 +1,64 @@
+config = $config;
+ }
+
+ public function menu(&$menu)
+ {
+ $menu[] = [
+ 'key' => 'starterkit',
+ 'title_link' => 'Starterkit'
+ ];
+ }
+
+ public function form(&$form, $data)
+ {
+ return $form->group('start-config-fieldset', 'fieldset', function ($form) use ($data) {
+ $form->legend('start-config-legend', 'Starterkit config')
+ ->group('start-start_check-group', 'div', function ($form) use ($data) {
+ $form->checkbox('start_check', 'start_check', [ 'checked' => $data[ 'start_check' ] ])
+ ->label('start-start_check-label', ' Start check.', [
+ 'for' => 'start_check'
+ ]);
+ }, [ 'class' => 'form-group' ])
+ ->group('system-start_text-group', 'div', function ($form) use ($data) {
+ $form->label('system-start_text-label', 'Start text')
+ ->text('start_text', 'start_text', [
+ 'class' => 'form-control',
+ 'required' => 1,
+ 'placeholder' => 'Text exemple',
+ 'value' => $data[ 'start_text' ]
+ ]);
+ }, [ 'class' => 'form-group' ]);
+ })
+ ->token()
+ ->submit('submit', 'Enregistrer', [ 'class' => 'btn btn-success' ]);
+ }
+
+ public function validator(&$validator)
+ {
+ $validator->setRules([
+ 'start_check' => '!required|bool',
+ 'start_text' => 'required|string|max:255'
+ ]);
+ }
+
+ public function before(&$validator, &$data)
+ {
+ $data = [
+ 'start_check' => $validator->getInput('start_check'),
+ 'start_text' => $validator->getInput('start_text')
+ ];
+ }
+}
diff --git a/Services/HookUser.php b/Services/HookUser.php
new file mode 100644
index 0000000..9bd25a9
--- /dev/null
+++ b/Services/HookUser.php
@@ -0,0 +1,28 @@
+ 'Voir starterkit',
+ 'starterkit.admin' => 'Voir l\'administration',
+ 'starterkit.show' => 'Voir le contenu',
+ 'starterkit.created' => 'Ajouter du contenu',
+ 'starterkit.edited' => 'Éditer du contenu',
+ 'starterkit.delete' => 'Supprimer du contenu',
+ ];
+ }
+
+ public function hookStarterkitCreated($req)
+ {
+ return 'starterkit.created';
+ }
+
+ public function hookStarterkitEdited($id, $req)
+ {
+ return 'starterkit.edited';
+ }
+}
diff --git a/Services/StarterkitHook.php b/Services/StarterkitHook.php
deleted file mode 100644
index 4f095bc..0000000
--- a/Services/StarterkitHook.php
+++ /dev/null
@@ -1,16 +0,0 @@
-query = $query;
- $this->schema = $schema;
- }
-}
diff --git a/config.json b/config.json
index fc61295..cc8d26d 100644
--- a/config.json
+++ b/config.json
@@ -5,7 +5,7 @@
"Starterkit": "Starterkit\\Controller\\Starterkit"
},
"version": "1.0",
- "description": "Pour démarrer votre module soosyze avec une base de code. ",
+ "description": "Pour démarrer votre module Soosyze avec une base de code :
CRUD, liens dans les menus, droits utilisateurs, page de configuration. ",
"package": "Development",
"locked": false,
"required": []