Created
October 3, 2016 15:58
-
-
Save richardhj/8a4852da792c5ade98c4db55be3f804f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Exemplified DCA for a merging a fileTree and fileUpload field in Contao Open Source CMS | |
* * Files can be via selected in the field "attachments" | |
* * Files can be uploaded in the field "attachments_upload". They will be merged to "attachments" | |
* | |
* @author Richard Henkenjohann <richardhenkenjohann@googlemail.com> | |
*/ | |
$table = MyModuleModel::getTable(); | |
$GLOBALS['TL_DCA'][$table] = [ | |
// Config | |
'config' => [ | |
'onsubmit_callback' => [ | |
function (\DataContainer $dc) { | |
$model = MyModuleModel::findByPk($dc->id); | |
$attachments = deserialize($model->attachments); | |
foreach (deserialize($model->attachments_upload, true) as $path) { | |
$attachments[] = Dbafs::addResource($path)->uuid; | |
} | |
$model->attachments = serialize($attachments); | |
$model->attachments_uplaod = ''; | |
$model->save(); | |
}, | |
], | |
], | |
// Fields | |
'fields' => [ | |
'attachments' => [ | |
'label' => &$GLOBALS['TL_LANG'][$table]['attachments'], | |
'exclude' => true, | |
'inputType' => 'fileTree', | |
'eval' => [ | |
'tl_class' => 'clr', | |
'multiple' => true, | |
'files' => true, | |
'filesOnly' => true, | |
'fieldType' => 'checkbox', | |
], | |
'sql' => "blob NULL", | |
], | |
'attachments_upload' => [ | |
'label' => &$GLOBALS['TL_LANG'][$table]['attachments'], | |
'exclude' => true, | |
'inputType' => 'fileUpload', | |
'eval' => [ | |
'tl_class' => 'w50', | |
'uploadFolder' => 'files/attachments', | |
], | |
'sql' => "text NULL", | |
], | |
], | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment