Skip to content

Instantly share code, notes, and snippets.

@jpdevries
Created July 3, 2013 23:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpdevries/5923886 to your computer and use it in GitHub Desktop.
Save jpdevries/5923886 to your computer and use it in GitHub Desktop.
Dynamically set current user's redactor.image_upload_path Setting based on the alias of the currently edited resource's parent
<?php
switch ($modx->event->name) {
case 'OnDocFormPrerender':
if(!$resource) return;
$key = 'redactor.image_upload_path';
$userId = $modx->user->get('id');
$usersetting = $modx->getObject('modUserSetting', array('key' => $key, 'user' => $userId));
if(!$usersetting) return;
$modx->log(modX::LOG_LEVEL_INFO,"RedactorSettingsManager read: $key, $userId, {$usersetting->get('value')}");
$parentID = $page_id = $resource->get('parent');
if(!$parentID) return;
$parent = $modx->getObject('modResource',$parentID);
$alias = $parent->get('alias');
$usersetting->set('value',"uploads/images/$alias/");
$usersetting->save();
$modx->log(modX::LOG_LEVEL_INFO,"RedactorSettingsManager update: $key, $userId, {$usersetting->get('value')}");
$contextKey = $modx->context->get('key');
unset($_SESSION["modx.$contextKey.user.config"]);
$modx->setOption('redactor.image_upload_path',"uploads/images/$alias/");
$modx->log(modX::LOG_LEVEL_INFO,"RedactorSettingsManager read system: {$modx->getOption('redactor.image_upload_path')}");
break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment