-
-
Save jonleverrier/33205b49bfd23e12fa9e542fe61851b4 to your computer and use it in GitHub Desktop.
Sample plugin to display the welcome screen to any new member login for the first time in MODX Revolution manager
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 | |
/** | |
* A sample plugin to display the "welcome message" to all users, login for the first time in Revo manager | |
* | |
* @var modX $modx | |
* @var array $scriptProperties | |
* @var modPlugin $this | |
* | |
* @see modPlugin::process() | |
* | |
* @event OnManagerPageBeforeRender | |
* @event OnUserFormSave | |
*/ | |
switch ($modx->event->name) { | |
case 'OnManagerPageBeforeRender': | |
// Here we need to check if we are displaying the "welcome" controller | |
if (!$modx->event->params['controller'] instanceof WelcomeManagerController) { | |
return; | |
} | |
// Assume we always want to display the welcome message, no matter how global welcome_screen setting is configured | |
$show = true; | |
// Check the current user "preference" | |
$setting = $modx->getObject('modUserSetting', [ | |
'key' => 'welcome_screen', | |
'user' => $modx->user->get('id'), | |
]); | |
if ($setting) { | |
// user option found, let's use it instead | |
$show = (bool) $setting->get('value'); | |
} | |
// Set the option temporarily so the welcome controller could do whatever it takes | |
$modx->setOption('welcome_screen', $show); | |
break; | |
case 'OnUserFormSave': | |
// A user is saved, let's make sure to process only when a user is created | |
if ($modx->event->params['mode'] !== modSystemEvent::MODE_NEW) { | |
return; | |
} | |
// User has just been created, assume we want to create a user setting | |
/** @var modUser $user */ | |
$user = $modx->event->params['object']; | |
// First make sure the setting does not already exist | |
/** @var modUserSetting||null $setting */ | |
$setting = $modx->getObject('modUserSetting', [ | |
'key' => 'welcome_screen', | |
'user' => $user->get('id'), | |
]); | |
if (!$setting) { | |
// No user setting found, let's create it! | |
/** @var modUserSetting $setting */ | |
$setting = $modx->newObject('modUserSetting'); | |
$setting->fromArray([ | |
'key' => 'welcome_screen', | |
'user' => $user->get('id'), | |
'xtype' => 'combo-boolean', | |
'area' => 'manager', | |
'namespace' => 'core', | |
], '', true); | |
} | |
$setting->set('value', true); | |
$setting->save(); | |
break; | |
} | |
return; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment