Created
July 3, 2013 23:56
-
-
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
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 | |
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