Merge pull request 'fix(admin): accept multi-value 发布类型 on header-nav save' (#281) from worktree-fix-theme-toggle-overlap into main
Reviewed-on: CYL/wordpress-theme-aksrt#281
This commit is contained in:
commit
bf4c019ab3
3 files changed
+16
-3
No files matched your search
@@ -134,7 +134,7 @@ export const pageDisplaySchemas = {
|
|||||||
{ label: '紫色', value: 'jb-purple' },
|
{ label: '紫色', value: 'jb-purple' },
|
||||||
{ label: '粉色', value: 'jb-pink' },
|
{ label: '粉色', value: 'jb-pink' },
|
||||||
], dependsOn: { key: 'header_newposts_enabled', value: true } },
|
], dependsOn: { key: 'header_newposts_enabled', value: true } },
|
||||||
{ key: 'header_newposts_types', label: '发布类型', type: 'select', multiple: true, default: ['post'], options: [
|
{ key: 'header_newposts_types', label: '发布类型', type: 'checkbox', default: ['post'], options: [
|
||||||
{ label: '文章', value: 'post' },
|
{ label: '文章', value: 'post' },
|
||||||
{ label: '帖子', value: 'topic' },
|
{ label: '帖子', value: 'topic' },
|
||||||
{ label: '商品', value: 'product' },
|
{ label: '商品', value: 'product' },
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ class SchemaPageDisplay {
|
|||||||
['label' => '紫色', 'value' => 'jb-purple'],
|
['label' => '紫色', 'value' => 'jb-purple'],
|
||||||
['label' => '粉色', 'value' => 'jb-pink'],
|
['label' => '粉色', 'value' => 'jb-pink'],
|
||||||
]],
|
]],
|
||||||
['key' => 'header_newposts_types', 'label' => '发布类型', 'type' => 'select', 'default' => ['post'], 'options' => [
|
['key' => 'header_newposts_types', 'label' => '发布类型', 'type' => 'checkbox', 'default' => ['post'], 'options' => [
|
||||||
['label' => '文章', 'value' => 'post'],
|
['label' => '文章', 'value' => 'post'],
|
||||||
['label' => '帖子', 'value' => 'topic'],
|
['label' => '帖子', 'value' => 'topic'],
|
||||||
['label' => '商品', 'value' => 'product'],
|
['label' => '商品', 'value' => 'product'],
|
||||||
|
|||||||
@@ -181,13 +181,26 @@ class SchemaProvider {
|
|||||||
|
|
||||||
if (in_array($type, ['select', 'radio'], true) && !empty($field['options'])) {
|
if (in_array($type, ['select', 'radio'], true) && !empty($field['options'])) {
|
||||||
$valid_values = array_column($field['options'], 'value');
|
$valid_values = array_column($field['options'], 'value');
|
||||||
if (!in_array($value, $valid_values, true)) {
|
// Multi-select: accept array values when schema.multiple is set
|
||||||
|
// (legacy / SPA may still use type=select multiple).
|
||||||
|
if (!empty($field['multiple']) && is_array($value)) {
|
||||||
|
foreach ($value as $item) {
|
||||||
|
if (!in_array($item, $valid_values, true)) {
|
||||||
|
$errors[] = sprintf('%s has an invalid value', $field['label'] ?? $key);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} elseif (!in_array($value, $valid_values, true)) {
|
||||||
$errors[] = sprintf('%s has an invalid value', $field['label'] ?? $key);
|
$errors[] = sprintf('%s has an invalid value', $field['label'] ?? $key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($type === 'checkbox' && !empty($field['options'])) {
|
if ($type === 'checkbox' && !empty($field['options'])) {
|
||||||
$valid_values = array_column($field['options'], 'value');
|
$valid_values = array_column($field['options'], 'value');
|
||||||
|
if (!is_array($value)) {
|
||||||
|
$errors[] = sprintf('%s must be an array', $field['label'] ?? $key);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
foreach ((array) $value as $item) {
|
foreach ((array) $value as $item) {
|
||||||
if (!in_array($item, $valid_values, true)) {
|
if (!in_array($item, $valid_values, true)) {
|
||||||
$errors[] = sprintf('%s has an invalid value', $field['label'] ?? $key);
|
$errors[] = sprintf('%s has an invalid value', $field['label'] ?? $key);
|
||||||
|
|||||||
Reference in new issue
Block a user