Skip to content

Commit b6cb5e3

Browse files
authored
Allow restricting subtypes and classes in link edit panel (#1057)
* Enhance `pimcore.helpers.editmode.openLinkEditPanel` with subtype and class-specific filters * Add support for the "link" field type in objects * Fix link editor initialization by replacing array with object for `config`
1 parent 1182469 commit b6cb5e3

4 files changed

Lines changed: 104 additions & 7 deletions

File tree

public/js/pimcore/helpers.js

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1895,11 +1895,41 @@ pimcore.helpers.editmode = {};
18951895
pimcore.helpers.editmode.openLinkEditPanel = function (data, callback, config) {
18961896
const TARGETS = ["", "_blank", "_self", "_top", "_parent"];
18971897
const TYPES = ["asset", "document", "object"];
1898+
const SUBTYPES = {
1899+
document: pimcore.globalmanager.get("document_search_types").filter(v => v !== "folder"),
1900+
asset: pimcore.globalmanager.get("asset_search_types").filter(v => v !== "folder"),
1901+
object: pimcore.globalmanager.get("object_search_types").filter(v => v !== "folder"),
1902+
};
18981903

18991904
config = config || {};
19001905
const disabledFields = config.disabledFields || [];
19011906
const allowedTargets = Ext.Array.intersect(TARGETS, config.allowedTargets || TARGETS);
19021907
const allowedTypes = Ext.Array.intersect(TYPES, config.allowedTypes || TYPES);
1908+
const allowedSubtypes = Object.fromEntries(Object.entries(SUBTYPES).map(([key, value]) => [
1909+
key,
1910+
config.allowedSubtypes?.[key]?.filter(v => v !== "folder").length
1911+
? Ext.Array.intersect(value, config.allowedSubtypes[key])
1912+
: value
1913+
]));
1914+
const allowedClasses = config.allowedClasses;
1915+
1916+
const dndAllowed = (data) => {
1917+
const type = data.elementType;
1918+
1919+
if (!allowedTypes.includes(type)) {
1920+
return false;
1921+
}
1922+
1923+
if (Array.isArray(allowedSubtypes?.[type]) && !allowedSubtypes[type].includes(data.type)) {
1924+
return false;
1925+
}
1926+
1927+
if (type === "object" && Array.isArray(allowedClasses) && !allowedClasses.includes(data.className)) {
1928+
return false;
1929+
}
1930+
1931+
return true;
1932+
};
19031933

19041934
const internalTypeField = new Ext.form.Hidden({
19051935
fieldLabel: 'internalType',
@@ -1952,7 +1982,7 @@ pimcore.helpers.editmode.openLinkEditPanel = function (data, callback, config) {
19521982
}
19531983

19541984
data = data.records[0].data;
1955-
if (data.type !== "folder" && allowedTypes.includes(data.elementType)) {
1985+
if (dndAllowed(data)) {
19561986
return Ext.dd.DropZone.prototype.dropAllowed;
19571987
}
19581988
}.bind(this),
@@ -1963,7 +1993,7 @@ pimcore.helpers.editmode.openLinkEditPanel = function (data, callback, config) {
19631993
}
19641994

19651995
data = data.records[0].data;
1966-
if (data.type !== "folder" && allowedTypes.includes(data.elementType)) {
1996+
if (dndAllowed(data)) {
19671997
internalTypeField.setValue(data.elementType);
19681998
linkTypeField.setValue('internal');
19691999
pathField.setValue(data.path);
@@ -1998,7 +2028,11 @@ pimcore.helpers.editmode.openLinkEditPanel = function (data, callback, config) {
19982028
return true;
19992029
}
20002030
}, {
2001-
type: allowedTypes
2031+
type: allowedTypes,
2032+
subtype: allowedSubtypes,
2033+
specific: {
2034+
classes: allowedClasses,
2035+
},
20022036
});
20032037
}
20042038
});

public/js/pimcore/object/classes/data/link.js

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,62 @@ pimcore.object.classes.data.link = Class.create(pimcore.object.classes.data.data
5757
fieldLabel: t("allowed_types") + '<br />' + t('allowed_types_hint'),
5858
name: "allowedTypes",
5959
id: 'allowedTypes',
60-
store: this.types,
60+
store: this.types.map((text) => ({text})),
6161
value: this.datax.allowedTypes,
6262
displayField: "text",
6363
valueField: "text",
6464
width: 400
6565
},
66+
{
67+
xtype: "multiselect",
68+
fieldLabel: t("allowed_asset_subtypes") + '<br />' + t('allowed_types_hint'),
69+
name: "allowedAssetSubtypes",
70+
id: 'allowedAssetSubtypes',
71+
store: pimcore.globalmanager.get('asset_search_types').filter(v => v !== "folder").map((text) => ({text})),
72+
value: this.datax.allowedAssetSubtypes,
73+
displayField: "text",
74+
valueField: "text",
75+
width: 400
76+
},
77+
{
78+
xtype: "multiselect",
79+
fieldLabel: t("allowed_document_subtypes") + '<br />' + t('allowed_types_hint'),
80+
name: "allowedDocumentSubtypes",
81+
id: 'allowedDocumentSubtypes',
82+
store: pimcore.globalmanager.get('document_search_types').filter(v => v !== "folder").map((text) => ({text})),
83+
value: this.datax.allowedDocumentSubtypes,
84+
displayField: "text",
85+
valueField: "text",
86+
width: 400
87+
},
88+
{
89+
xtype: "multiselect",
90+
fieldLabel: t("allowed_object_subtypes") + '<br />' + t('allowed_types_hint'),
91+
name: "allowedObjectSubtypes",
92+
id: 'allowedObjectSubtypes',
93+
store: pimcore.globalmanager.get('object_search_types').filter(v => v !== "folder").map((text) => ({text})),
94+
value: this.datax.allowedObjectSubtypes,
95+
displayField: "text",
96+
valueField: "text",
97+
width: 400
98+
},
99+
{
100+
xtype: "multiselect",
101+
fieldLabel: t("allowed_classes") + '<br />' + t('allowed_types_hint'),
102+
name: "allowedClasses",
103+
id: 'allowedClasses',
104+
store: pimcore.globalmanager.get("object_types_store"),
105+
value: this.datax.allowedClasses,
106+
displayField: "text",
107+
valueField: "text",
108+
width: 400
109+
},
66110
{
67111
xtype: "multiselect",
68112
fieldLabel: t("allowed_targets") + '<br />' + t('allowed_types_hint'),
69113
name: "allowedTargets",
70114
id: 'allowedTargets',
71-
store: this.targets,
115+
store: this.targets.map((text) => ({text})),
72116
value: this.datax.allowedTargets,
73117
displayField: "text",
74118
valueField: "text",
@@ -79,7 +123,7 @@ pimcore.object.classes.data.link = Class.create(pimcore.object.classes.data.data
79123
fieldLabel: t("disabled_fields") + '<br />' + t('allowed_types_hint'),
80124
name: "disabledFields",
81125
id: 'disabledFields',
82-
store: this.fields,
126+
store: this.fields.map((text) => ({text})),
83127
value: this.datax.disabledFields,
84128
displayField: "text",
85129
valueField: "text",

public/js/pimcore/object/tags/link.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,27 @@ pimcore.object.tags.link = Class.create(pimcore.object.tags.abstract, {
139139
},
140140

141141
openEditor: function () {
142-
let config = [];
142+
let config = {};
143+
let allowedSubtypes = {};
143144

144145
if (!empty(this.fieldConfig.allowedTypes)){
145146
config['allowedTypes'] = this.fieldConfig.allowedTypes;
146147
}
148+
if (!empty(this.fieldConfig.allowedAssetSubtypes)){
149+
allowedSubtypes['asset'] = this.fieldConfig.allowedAssetSubtypes;
150+
}
151+
if (!empty(this.fieldConfig.allowedDocumentSubtypes)){
152+
allowedSubtypes['document'] = this.fieldConfig.allowedDocumentSubtypes;
153+
}
154+
if (!empty(this.fieldConfig.allowedObjectSubtypes)){
155+
allowedSubtypes['object'] = this.fieldConfig.allowedObjectSubtypes;
156+
}
157+
if (!empty(allowedSubtypes)) {
158+
config['allowedSubtypes'] = allowedSubtypes;
159+
}
160+
if (!empty(this.fieldConfig.allowedClasses)){
161+
config['allowedClasses'] = this.fieldConfig.allowedClasses;
162+
}
147163
if (!empty(this.fieldConfig.allowedTargets)){
148164
config['allowedTargets'] = this.fieldConfig.allowedTargets;
149165
}

translations/admin_ext.en.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,9 @@ visibility_of_system_properties: Visibility of system properties
250250
translate: translate
251251
translations_admin_hint: 'HINT: Please Reload UI to apply translation changes!'
252252
allowed_types: Allowed Types
253+
allowed_asset_subtypes: Allowed Subtypes for Assets
254+
allowed_document_subtypes: Allowed Subtypes for Documents
255+
allowed_object_subtypes: Allowed Subtypes for Objects
253256
allowed_targets: Allowed Targets
254257
disabled_fields: Disabled Fields
255258
columnlength: Columnlength

0 commit comments

Comments
 (0)