fix(navigation): stop mangling zibsvg/customsvg menu icons
aksrt_render_menu_icon() prefixed any value without an fa substring with fa fas fa-, turning picker values like zibsvg-hot into fa fas fa-zibsvg-hot — blank icons in the frontend nav. Sprite and inline SVG values now flow through aksrt_icon_markup with the menu-item-icon classes attached; FA values keep the legacy padding.
This commit is contained in:
@@ -45,20 +45,30 @@ function aksrt_get_menu_item_decoration($menu_item): array {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $icon_class FA5 icon class.
|
||||
* @param string $icon_class Icon-picker value (FA5 class, zibsvg- or customsvg-).
|
||||
* @param bool $enabled Global switch.
|
||||
*/
|
||||
function aksrt_render_menu_icon(string $icon_class, bool $enabled = true): string {
|
||||
if (!$enabled || $icon_class === '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
// Sprite/inline values must reach aksrt_icon_markup untouched — the legacy
|
||||
// fa-prefix padding below would corrupt them (zibsvg-hot → fa fas fa-zibsvg-hot).
|
||||
if (str_starts_with($icon_class, 'zibsvg-')) {
|
||||
return aksrt_icon_markup($icon_class, 'icon mr3 menu-item-icon');
|
||||
}
|
||||
if (str_starts_with($icon_class, 'customsvg-')) {
|
||||
return aksrt_icon_markup($icon_class, 'mr3 menu-item-icon');
|
||||
}
|
||||
|
||||
// legacy uses the Font Awesome 5 `fa` prefix.
|
||||
if (strpos($icon_class, 'fa') === false) {
|
||||
$icon_class = 'fa fas fa-' . ltrim($icon_class, '-');
|
||||
} elseif (strpos($icon_class, 'fa-') === 0 && strpos($icon_class, ' ') === false) {
|
||||
$icon_class = 'fa ' . $icon_class;
|
||||
}
|
||||
return '<i class="' . esc_attr($icon_class) . ' mr3 menu-item-icon" aria-hidden="true"></i>';
|
||||
return aksrt_icon_markup($icon_class, 'mr3 menu-item-icon');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -90,6 +90,34 @@ test('FA5 loads under a single canonical handle everywhere', () => {
|
||||
}
|
||||
});
|
||||
|
||||
test('custom settings pages and standalone save paths speak the three icon formats', () => {
|
||||
// 手机底部Tab / 右侧悬浮按钮 custom pages render the shared picker.
|
||||
for (const page of ['assets/admin/src/pages/content/FooterTabbarSettings.vue', 'assets/admin/src/pages/content/FloatingButtonsSettings.vue']) {
|
||||
const source = read(page);
|
||||
assert.match(source, /import FaIconPicker from '@\/components\/form\/FaIconPicker\.vue'/);
|
||||
assert.match(source, /import IconValue from '@\/components\/form\/IconValue\.vue'/);
|
||||
assert.match(source, /<FaIconPicker/, `${page} uses the picker for icon fields`);
|
||||
}
|
||||
// Their REST save paths keep customsvg markup intact.
|
||||
const controller = read('src/Admin/GlobalControllerPart1.php');
|
||||
assert.match(controller, /aksrt_sanitize_icon_value\(/);
|
||||
assert.doesNotMatch(controller, /preg_match\('\/\^fa\\s\+/, 'no FA-only regex gate on icon fields');
|
||||
// Frontend consumers render every format.
|
||||
const footer = read('footer.php');
|
||||
assert.match(footer, /aksrt_icon_markup\(\(string\) \$tab_icon\)/);
|
||||
assert.match(footer, /aksrt_icon_markup\(\(string\) \$item_icon\)/);
|
||||
assert.match(read('inc/helpers/aksrt-runtime-win.php'), /aksrt_icon_markup\(\$icon\)/);
|
||||
// The popover tabs must wrap instead of overflowing the panel.
|
||||
assert.match(read('assets/admin/src/components/form/FaIconPicker.vue'), /flex-wrap: wrap/);
|
||||
});
|
||||
|
||||
test('nav menu icons render every format without legacy fa-prefix mangling', () => {
|
||||
const helper = read('inc/helpers/menu-decoration.php');
|
||||
assert.match(helper, /str_starts_with\(\$icon_class, 'zibsvg-'\)/);
|
||||
assert.match(helper, /aksrt_icon_markup\(\$icon_class, 'icon mr3 menu-item-icon'\)/);
|
||||
assert.doesNotMatch(helper, /'<i class="' \. esc_attr\(\$icon_class\)/, 'no raw i-tag bypassing the unified helper');
|
||||
});
|
||||
|
||||
test('brand icons render despite the zibll-legacy fa-fab double prefix', () => {
|
||||
const rule = /\.fa\.fab\{font-family:"Font Awesome 5 Brands";font-weight:400\}/;
|
||||
for (const file of ['assets/css/main.css', 'assets/css/admin-icon-picker.css', 'assets/admin/src/style.css']) {
|
||||
|
||||
Reference in New Issue
Block a user