add Hooks
This commit is contained in:
+8
-1
@@ -16,11 +16,13 @@ public class GlobalControllerAdvice {
|
||||
|
||||
private final SettingService settingService;
|
||||
private final com.sisvietnamvn.web.service.MenuService menuService;
|
||||
private final com.sisvietnamvn.web.hook.HookManager hookManager;
|
||||
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.menuService = menuService;
|
||||
this.hookManager = hookManager;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -64,6 +66,11 @@ public class GlobalControllerAdvice {
|
||||
return getWidgets("footer");
|
||||
}
|
||||
|
||||
@ModelAttribute("hookManager")
|
||||
public com.sisvietnamvn.web.hook.HookManager getHookManager() {
|
||||
return hookManager;
|
||||
}
|
||||
|
||||
@ModelAttribute("themeModPrimaryColor")
|
||||
public String getThemeModPrimaryColor() {
|
||||
return settingService.getValue("theme_mod_primaryColor", "#007bff");
|
||||
|
||||
@@ -50,13 +50,18 @@ public class HookManager {
|
||||
/**
|
||||
* Executes an action and returns an empty string.
|
||||
* 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) {
|
||||
doAction(hookName, args);
|
||||
return "";
|
||||
}
|
||||
|
||||
public String doActionAndReturn(String hookName) {
|
||||
doAction(hookName);
|
||||
return "";
|
||||
}
|
||||
|
||||
// --- Filters ---
|
||||
|
||||
public <T> void addFilter(String hookName, FilterCallback<T> callback, int priority) {
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
<!-- Project-wide CSS Variables & Custom Styles -->
|
||||
<link rel="stylesheet" th:href="@{/css/custom.css}">
|
||||
<!-- Admin Head Hook -->
|
||||
<th:block th:utext="${@hookManager.doActionAndReturn('admin_head')}"></th:block>
|
||||
<th:block th:utext="${hookManager.doActionAndReturn('admin_head')}"></th:block>
|
||||
</head>
|
||||
|
||||
<body id="page-top">
|
||||
@@ -361,7 +361,7 @@
|
||||
<section layout:fragment="scripts"></section>
|
||||
|
||||
<!-- Admin Footer Hook -->
|
||||
<th:block th:utext="${@hookManager.doActionAndReturn('admin_footer')}"></th:block>
|
||||
<th:block th:utext="${hookManager.doActionAndReturn('admin_footer')}"></th:block>
|
||||
|
||||
</body>
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<style th:utext="${themeCss}"></style>
|
||||
|
||||
<!-- wp_head hook -->
|
||||
<th:block th:utext="${@hookManager.doActionAndReturn('wp_head')}"></th:block>
|
||||
<th:block th:utext="${hookManager.doActionAndReturn('wp_head')}"></th:block>
|
||||
</head>
|
||||
<body>
|
||||
<!-- Replace with Header Fragment -->
|
||||
@@ -32,6 +32,6 @@
|
||||
<footer th:replace="~{themes/__${activeTheme}__/footer :: footer}"></footer>
|
||||
|
||||
<!-- wp_footer hook -->
|
||||
<th:block th:utext="${@hookManager.doActionAndReturn('wp_footer')}"></th:block>
|
||||
<th:block th:utext="${hookManager.doActionAndReturn('wp_footer')}"></th:block>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<style th:utext="${themeCss}"></style>
|
||||
|
||||
<!-- wp_head hook -->
|
||||
<th:block th:utext="${@hookManager.doActionAndReturn('wp_head')}"></th:block>
|
||||
<th:block th:utext="${hookManager.doActionAndReturn('wp_head')}"></th:block>
|
||||
</head>
|
||||
<body style="background-color: #f8f9fa; font-family: sans-serif;">
|
||||
<!-- Replace with Header Fragment -->
|
||||
@@ -33,6 +33,6 @@
|
||||
<footer th:replace="~{themes/__${activeTheme}__/footer :: footer}"></footer>
|
||||
|
||||
<!-- wp_footer hook -->
|
||||
<th:block th:utext="${@hookManager.doActionAndReturn('wp_footer')}"></th:block>
|
||||
<th:block th:utext="${hookManager.doActionAndReturn('wp_footer')}"></th:block>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user