Skip to content

Commit

Permalink
Adjust chunk on page settings and tvs to output the name instead of t…
Browse files Browse the repository at this point in the history
…he ID

Signed-off-by: matdave <[email protected]>
  • Loading branch information
matdave committed Nov 5, 2024
1 parent 1479d6e commit be497eb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
20 changes: 14 additions & 6 deletions _build/assets/js/Components/Sidebar/PageSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down
10 changes: 8 additions & 2 deletions _build/assets/js/UI/Inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
5 changes: 3 additions & 2 deletions core/components/fred/src/Traits/Endpoint/Ajax/GetChunks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'),
Expand Down

0 comments on commit be497eb

Please sign in to comment.