Skip to content

Instantly share code, notes, and snippets.

@Semdevmaster
Created March 7, 2018 13:40
Show Gist options
  • Select an option

  • Save Semdevmaster/6b76431fc0fca15062d7bc39b2655ab0 to your computer and use it in GitHub Desktop.

Select an option

Save Semdevmaster/6b76431fc0fca15062d7bc39b2655ab0 to your computer and use it in GitHub Desktop.
Смена источника файлов для определённых шаблонов
<?php
if (($modx->event->name == 'OnDocFormSave' && $mode == 'new') || ($modx->event->name == 'OnDocFormRender' && $mode == 'upd')) {
switch ($resource->get('template')) {
//ID шаблонов страниц
case 1:
case 2:
case 3:
//ID источника файлов
$source = 1;
break;
case 4:
case 5:
$source = 2;
break;
}
if ($source) {
$properties = $resource->get('properties');
$properties['ms2gallery'] = array('media_source' => $source);
$resource->set('properties', $properties);
if ($modx->event->name == 'OnDocFormSave') {
$resource->save();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment