add Hooks

This commit is contained in:
2026-07-02 19:21:25 +07:00
parent 0dd68c3649
commit 3dc5a03484
5 changed files with 20 additions and 8 deletions
@@ -16,11 +16,13 @@ public class GlobalControllerAdvice {
private final SettingService settingService; private final SettingService settingService;
private final com.sisvietnamvn.web.service.MenuService menuService; private final com.sisvietnamvn.web.service.MenuService menuService;
private final com.sisvietnamvn.web.hook.HookManager hookManager;
private final PathMatchingResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver(); private final PathMatchingResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver();
public GlobalControllerAdvice(SettingService settingService, com.sisvietnamvn.web.service.MenuService menuService) { public GlobalControllerAdvice(SettingService settingService, com.sisvietnamvn.web.service.MenuService menuService, com.sisvietnamvn.web.hook.HookManager hookManager) {
this.settingService = settingService; this.settingService = settingService;
this.menuService = menuService; this.menuService = menuService;
this.hookManager = hookManager;
} }
/** /**
@@ -64,6 +66,11 @@ public class GlobalControllerAdvice {
return getWidgets("footer"); return getWidgets("footer");
} }
@ModelAttribute("hookManager")
public com.sisvietnamvn.web.hook.HookManager getHookManager() {
return hookManager;
}
@ModelAttribute("themeModPrimaryColor") @ModelAttribute("themeModPrimaryColor")
public String getThemeModPrimaryColor() { public String getThemeModPrimaryColor() {
return settingService.getValue("theme_mod_primaryColor", "#007bff"); return settingService.getValue("theme_mod_primaryColor", "#007bff");
@@ -50,13 +50,18 @@ public class HookManager {
/** /**
* Executes an action and returns an empty string. * Executes an action and returns an empty string.
* This is useful for invoking actions directly within Thymeleaf templates * This is useful for invoking actions directly within Thymeleaf templates
* (e.g., <th:block th:text="${@hookManager.doActionAndReturn('wp_head')}"></th:block>). * (e.g., <th:block th:text="${hookManager.doActionAndReturn('wp_head')}"></th:block>).
*/ */
public String doActionAndReturn(String hookName, Object... args) { public String doActionAndReturn(String hookName, Object... args) {
doAction(hookName, args); doAction(hookName, args);
return ""; return "";
} }
public String doActionAndReturn(String hookName) {
doAction(hookName);
return "";
}
// --- Filters --- // --- Filters ---
public <T> void addFilter(String hookName, FilterCallback<T> callback, int priority) { public <T> void addFilter(String hookName, FilterCallback<T> callback, int priority) {
@@ -20,7 +20,7 @@
<!-- Project-wide CSS Variables & Custom Styles --> <!-- Project-wide CSS Variables & Custom Styles -->
<link rel="stylesheet" th:href="@{/css/custom.css}"> <link rel="stylesheet" th:href="@{/css/custom.css}">
<!-- Admin Head Hook --> <!-- Admin Head Hook -->
<th:block th:utext="${@hookManager.doActionAndReturn('admin_head')}"></th:block> <th:block th:utext="${hookManager.doActionAndReturn('admin_head')}"></th:block>
</head> </head>
<body id="page-top"> <body id="page-top">
@@ -361,7 +361,7 @@
<section layout:fragment="scripts"></section> <section layout:fragment="scripts"></section>
<!-- Admin Footer Hook --> <!-- Admin Footer Hook -->
<th:block th:utext="${@hookManager.doActionAndReturn('admin_footer')}"></th:block> <th:block th:utext="${hookManager.doActionAndReturn('admin_footer')}"></th:block>
</body> </body>
@@ -7,7 +7,7 @@
<style th:utext="${themeCss}"></style> <style th:utext="${themeCss}"></style>
<!-- wp_head hook --> <!-- wp_head hook -->
<th:block th:utext="${@hookManager.doActionAndReturn('wp_head')}"></th:block> <th:block th:utext="${hookManager.doActionAndReturn('wp_head')}"></th:block>
</head> </head>
<body> <body>
<!-- Replace with Header Fragment --> <!-- Replace with Header Fragment -->
@@ -32,6 +32,6 @@
<footer th:replace="~{themes/__${activeTheme}__/footer :: footer}"></footer> <footer th:replace="~{themes/__${activeTheme}__/footer :: footer}"></footer>
<!-- wp_footer hook --> <!-- wp_footer hook -->
<th:block th:utext="${@hookManager.doActionAndReturn('wp_footer')}"></th:block> <th:block th:utext="${hookManager.doActionAndReturn('wp_footer')}"></th:block>
</body> </body>
</html> </html>
@@ -7,7 +7,7 @@
<style th:utext="${themeCss}"></style> <style th:utext="${themeCss}"></style>
<!-- wp_head hook --> <!-- wp_head hook -->
<th:block th:utext="${@hookManager.doActionAndReturn('wp_head')}"></th:block> <th:block th:utext="${hookManager.doActionAndReturn('wp_head')}"></th:block>
</head> </head>
<body style="background-color: #f8f9fa; font-family: sans-serif;"> <body style="background-color: #f8f9fa; font-family: sans-serif;">
<!-- Replace with Header Fragment --> <!-- Replace with Header Fragment -->
@@ -33,6 +33,6 @@
<footer th:replace="~{themes/__${activeTheme}__/footer :: footer}"></footer> <footer th:replace="~{themes/__${activeTheme}__/footer :: footer}"></footer>
<!-- wp_footer hook --> <!-- wp_footer hook -->
<th:block th:utext="${@hookManager.doActionAndReturn('wp_footer')}"></th:block> <th:block th:utext="${hookManager.doActionAndReturn('wp_footer')}"></th:block>
</body> </body>
</html> </html>