Skip to content

Instantly share code, notes, and snippets.

@udovichenko
Last active September 5, 2018 11:42
Show Gist options
  • Save udovichenko/ae5884fc3d79368298d0236fa91ef51e to your computer and use it in GitHub Desktop.
Save udovichenko/ae5884fc3d79368298d0236fa91ef51e to your computer and use it in GitHub Desktop.
MODX defaultTemplateSource plugin
<?php
if ($modx->event->name == 'OnDocFormSave') {
// ms2Gallery
$templateSources = array(
4 => 3, // templateId => sourceId
);
// minishop Gallery
$minishopTemplateSources = array(
22 => 16 // templateId => sourceId
);
// ms2Gallery
foreach ($templateSources as $key => $val) {
if ($resource->get('template') == $key) { // наш шаблон
$properties = $modx->fromJSON($resource->get('properties'));
$properties['ms2gallery'] = array('media_source' => $val); // его источник файлов
$resource->set('properties', $modx->toJSON($properties));
$resource->save();
}
}
// minishop Gallery
foreach ($minishopTemplateSources as $key => $val) {
if ($resource->get('template') == $key) { // наш шаблон
$resource->set('source', $val);
$resource->save();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment