Skip to content

Commit fe8edac

Browse files
committed
Update Elements creation
Adds logic to prevent the category request param from interfering with the display of certain grids and their category filtering combo; clarifies what that param signifies in the URL and how it's used
1 parent 31d0f6d commit fe8edac

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed

Diff for: manager/assets/modext/widgets/core/modx.grid.js

+12
Original file line numberDiff line numberDiff line change
@@ -1292,6 +1292,18 @@ Ext.extend(MODx.grid.Grid,Ext.grid.EditorGridPanel,{
12921292
}
12931293
return config;
12941294
}
1295+
1296+
/**
1297+
* Get the request value for a grid's category filtering. Derives whether the category param is to be applied to a
1298+
* grid and its category filter based on the existence of the tab param in the GET request. Needed where the same
1299+
* category processor is used for different purposes within the same editing panel (notably the Template and TV panels).
1300+
*/
1301+
,getCategoryFilterValue: () => {
1302+
if (typeof MODx.request.tab === 'undefined' || typeof MODx.request.category === 'undefined') {
1303+
return null;
1304+
}
1305+
return Math.abs(parseInt(MODx.request.category, 10));
1306+
}
12951307
});
12961308

12971309
/* local grid */

Diff for: manager/assets/modext/widgets/element/modx.grid.template.tv.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ MODx.grid.TemplateTV = function(config = {}) {
3232
action: 'Element/Template/TemplateVar/GetList',
3333
template: config.template,
3434
sort: 'tv_rank',
35-
category: MODx.request.category || null
35+
category: this.getCategoryFilterValue()
3636
},
3737
saveParams: {
3838
template: config.template
@@ -94,7 +94,7 @@ MODx.grid.TemplateTV = function(config = {}) {
9494
xtype: 'modx-combo-category',
9595
itemId: 'filter-category',
9696
emptyText: _('filter_by_category'),
97-
value: MODx.request.category !== 'undefined' ? MODx.request.category : null,
97+
value: this.getCategoryFilterValue(),
9898
submitValue: false,
9999
hiddenName: '',
100100
width: 200,

Diff for: manager/assets/modext/widgets/element/modx.grid.tv.template.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ MODx.grid.TemplateVarTemplate = function(config = {}) {
3030
baseParams: {
3131
action: 'Element/TemplateVar/Template/GetList',
3232
tv: config.tv,
33-
category: MODx.request.category || null
33+
category: this.getCategoryFilterValue()
3434
},
3535
saveParams: {
3636
tv: config.tv
@@ -68,7 +68,7 @@ MODx.grid.TemplateVarTemplate = function(config = {}) {
6868
xtype: 'modx-combo-category',
6969
itemId: 'filter-category',
7070
emptyText: _('filter_by_category'),
71-
value: MODx.request.category !== 'undefined' ? MODx.request.category : null,
71+
value: this.getCategoryFilterValue(),
7272
submitValue: false,
7373
hiddenName: '',
7474
width: 200,

Diff for: manager/assets/modext/widgets/element/modx.tree.element.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,15 @@ Ext.extend(MODx.tree.Element, MODx.tree.Tree, {
363363
},
364364

365365
_createElement: function(item, e, t) {
366-
const elementIdentifiers = this.extractElementIdentifiersFromActiveNode(this.cm.activeNode);
367-
this.redirect(`?a=element/${elementIdentifiers.type}/create&category=${elementIdentifiers.categoryId}`);
366+
const
367+
elementIdentifiers = this.extractElementIdentifiersFromActiveNode(this.cm.activeNode),
368+
{ type, categoryId } = elementIdentifiers
369+
;
370+
let path = `?a=element/${type}/create`;
371+
if (!Ext.isEmpty(categoryId)) {
372+
path += `&category=${categoryId}`;
373+
}
374+
this.redirect(path);
368375
this.cm.hide();
369376
return false;
370377
},

0 commit comments

Comments
 (0)