diff --git a/_build/assets/js/Components/Sidebar/PageSettings.js b/_build/assets/js/Components/Sidebar/PageSettings.js index 92cf26ad..ab96b932 100644 --- a/_build/assets/js/Components/Sidebar/PageSettings.js +++ b/_build/assets/js/Components/Sidebar/PageSettings.js @@ -257,7 +257,7 @@ export default class PageSettings extends SidebarPlugin { case 'page': return ui.page(setting, {id: defaultValue, url: ''}, this.setThemeSettingWithEmitter); case 'chunk': - return ui.chunk(setting, {id: defaultValue, name: ''}, this.setThemeSettingWithEmitter); + return ui.chunk(setting, {id: 0, name: defaultValue}, this.setThemeSettingWithEmitter); case 'tagger': return ui.tagger(setting, defaultValue, this.setThemeSettingWithEmitter); case 'image': @@ -387,7 +387,7 @@ export default class PageSettings extends SidebarPlugin { fields.appendChild(ui.toggleGroup(tv, this.pageSettings.tvs[tv.name], this.setMultiTVWithEmitter, this.addTVChangeListener)); break; case 'chunk': - fields.appendChild(ui.chunk(tv, { id: this.pageSettings.tvs[tv.name], name: ''}, this.setTVWithEmitter, this.addTVChangeListener)); + fields.appendChild(ui.chunk(tv, { id: 0, name: this.pageSettings.tvs[tv.name]}, this.setTVWithEmitter, this.addTVChangeListener)); default: fields.appendChild(ui.text(tv, this.pageSettings.tvs[tv.name], this.setTVWithEmitter, this.addTVChangeListener)); } @@ -436,8 +436,12 @@ export default class PageSettings extends SidebarPlugin { } setThemeSettingWithEmitter(name, value, input) { - if (typeof value === 'object' && value.id) { - value = value.id; + if (typeof value === 'object') { + if (typeof value.name !== 'undefined') { + value = value.name; + } else if (typeof value.id !== 'undefined') { + value = value.id; + } } this.setThemeSetting(name, value); @@ -475,8 +479,12 @@ export default class PageSettings extends SidebarPlugin { } setTVWithEmitter(name, value, input) { - if (typeof value === 'object' && value.id) { - value = value.id; + if (typeof value === 'object') { + if (typeof value.name !== 'undefined') { + value = value.name; + } else if (typeof value.id !== 'undefined') { + value = value.id; + } } this.setSetting(name, value, 'tvs'); emitter.emit('fred-page-setting-change', 'tv_' + name, value, valueParser(value), input); diff --git a/_build/assets/js/UI/Inputs.ts b/_build/assets/js/UI/Inputs.ts index bae9ff45..a9c12d9f 100644 --- a/_build/assets/js/UI/Inputs.ts +++ b/_build/assets/js/UI/Inputs.ts @@ -761,14 +761,20 @@ export const chunk = ( } chunkChoices.ajax(callback => { - getChunks(defaultValue.id, queryOptions) + let defaultSearch: string | number = ''; + if (defaultValue.id) { + defaultSearch = defaultValue.id; + } else if (defaultValue.name) { + defaultSearch = defaultValue.name; + } + getChunks(defaultSearch, queryOptions) .then(json => { initData = json.data.chunks; callback(json.data.chunks, 'value', 'name'); if (json.data.current) { chunkChoices.setChoices([json.data.current], 'value', 'name', false); - chunkChoices.setValueByChoice("" + defaultValue.id); + chunkChoices.setValueByChoice(json.data.current.value); } }) .catch(error => { diff --git a/core/components/fred/src/Traits/Endpoint/Ajax/GetChunks.php b/core/components/fred/src/Traits/Endpoint/Ajax/GetChunks.php index 9b1bab94..33f1a8ed 100644 --- a/core/components/fred/src/Traits/Endpoint/Ajax/GetChunks.php +++ b/core/components/fred/src/Traits/Endpoint/Ajax/GetChunks.php @@ -21,7 +21,7 @@ trait GetChunks public function process() { $query = $_GET['query']; - $current = isset($_GET['current']) ? (int)$_GET['current'] : 0; + $current = isset($_GET['current']) ? $_GET['current'] : 0; $category = $_GET['category'] ?? ''; $chunks = $_GET['chunks'] ?? ''; $limit = isset($_GET['limit']) ? (int)$_GET['limit'] : 25; @@ -58,7 +58,8 @@ public function process() $currentChunk = null; if (!empty($current)) { /** @var $currentChunk */ - $currentChunk = $this->modx->getObject($this->chunkClass, $current); + $currentWhere = (is_numeric($current)) ? ['id' => $current] : ['name' => $current]; + $currentChunk = $this->modx->getObject($this->chunkClass, $currentWhere); if ($currentChunk) { $currentChunk = [ 'id' => $currentChunk->get('id'),