Hi, I would like to create in MIGX a multifile-uploader (images) that would work the same as for a single file (image). That is, I can select few images from disk and choose the source where to save them and then select few images at once from which items will be created in migx.
I tried in the “Actionbuttons” tab to add buttons: “upload”, ‘uploadfiles’ but each of them does not have the ability to choose where to save the files, they are rigidly saved in the selected source or in a folder with a document id according to :
I don’t think there is build-in functionality in MIGX for this use case.
But you could try creating a custom action-button.
Here is an example (that may or may not work for your use case):
Create a custom folder in core/components. For example with the name “mymigx”.
In this folder create a file grid.config.inc.php in the subfolder migxconfigs/grid ( → core/components/mymigx/migxconfigs/grid/grid.config.inc.php.
Add the code below to this file grid.config.inc.php.
In the MIGX configuration → tab “MIGXdb-Settings” → set the field “Package” to the name of the folder. (“mymigx” in this case.)
Save the MIGX config, open it again and choose the (newly added) option “multiselect” in the tab “Actionbuttons”.
grid.config.inc.php
<?php
$gridactionbuttons['multiselect']['text'] = "'Multiselect'";
$gridactionbuttons['multiselect']['handler'] = 'this.selectMultipleImages';
$gridactionbuttons['multiselect']['scope'] = 'this';
$gridactionbuttons['multiselect']['standalone'] = '1';
$gridfunctions['this.selectMultipleImages'] = "
selectMultipleImages: function(btn,e) {
this.browser = MODx.load({
xtype: 'modx-browser'
,closeAction: 'close'
,id: Ext.id()
,multiple: true
,source: [[+config.media_source_id]] || MODx.config.default_media_source
,hideFiles: this.config.hideFiles || false
,rootVisible: this.config.rootVisible || false
,allowedFileTypes: this.config.allowedFileTypes || ''
,wctx: this.config.wctx || 'web'
,openTo: this.config.openTo || ''
,rootId: this.config.rootId || '/'
,hideSourceCombo: this.config.hideSourceCombo || false
,listeners: {
'select': {fn: function(data) { // 'data' only contains the first selected file
nodes = this.browser.win.view.getSelectedNodes(); // Get all the selected files from the browser
for (var i = 0; i < nodes.length; i++) {
var data = this.browser.win.view.lookup[nodes[i].id];
var img_path = data['fullRelativeUrl'];
this.addNewItem({ img: img_path}); // Assuming 'img' is the name of the image field in the MIGX config
}
}, scope:this}
}
});
this.browser.show(btn);
return true;
}
";
Adapt this code to your needs.
The code is based on the action-button “importcsvmigx” in the MIGX code:
The xtype modx-browser is the MODX file browser (in your 2nd screenshot). The listener “select” runs, when the OK-button in the MODX browser is clicked.
This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.