So, what I ended up doing for this is basically duplicating the existing Profile files:
1. System->Actions, created a new action under security:
Controller: security/ext-profile
Namespace: core
Load Headers: [checked]
Language Topics: user
2. Updated the existing Profile menu item to use the Action: core - security/ext-profile. (Note: You can do this last if you don't want to break the profile editor while you're working on it.)
3. Created /manager/controllers/default/security/ext-profile/ and copied into it index.php from /manager/controllers/default/security/profile/
4. Edited the above index.php, changing:
$modx->regClientStartupScript($modx->getOption('manager_url').'assets/modext/sections/security/profile/update.js');
to
$modx->regClientStartupScript($modx->getOption('manager_url').'assets/modext/sections/security/ext-profile/update.js');
also changed:
return $modx->smarty->fetch('security/profile/index.tpl');
to:
return $modx->smarty->fetch('security/ext-profile/index.tpl');
And added:
$modx->regClientStartupScript($modx->getOption('manager_url').'assets/modext/widgets/core/modx.combo.js');
5. Created /manager/templates/default/security/ext-profile/ and copied into it index.tpl from /manager/templates/default/security/profile/
6. Not really necessary, but I updated the above index.tpl and changed:
<div id="modx-panel-profile-div"></div>
to:
<div id="modx-panel-ext-profile-div"></div>
7. Created /manager/assets/modext/sections/security/ext-profile/ and copied into it update.js from /manager/assets/modext/sections/security/profile/
8. Updated update.js file in... all kinds of ways. Changed:
,renderTo: 'modx-panel-profile-div'
to:
,renderTo: 'modx-panel-ext-profile-div'
Changed all instances of:
url: MODx.config.connectors_url + 'security/profile.php'
to:
url: MODx.config.connectors_url + 'security/ext-profile.php'
Added other fields I wanted from the Users editor (/manager/assets/modext/sections/security/user/update.js), such as:
{
xtype: 'textfield'
,fieldLabel: _('user_website')
,name: 'website'
,width: 300
,maxLength: 255
}
I also copied the MODx.combo.Gender code from /manager/assets/modext/widgets/security/modx.panel.user.js so I could add the gender field:
{
xtype: 'modx-combo-gender'
,fieldLabel: _('user_gender')
,hiddenName: 'gender'
,name: 'gender'
}
Once I added all of the standard profile fields, I created the new fields I wanted added. I began all of their names with 'ext_' to make life easier:
{
xtype: 'textfield'
,fieldLabel: 'Facebook URL: '
,name: 'ext_facebook'
,maxLength: 255
,width: 300
}
9. In /connectors/security, I copied profile.php to ext-profile.php. In it, I changed:
$modx->request->handleRequest(array('location' => 'security/profile'));
to:
$modx->request->handleRequest(array('location' => 'security/ext-profile'));
10. I created /core/model/modx/processors/security/ext-profile/ and copied into it all three files from /core/model/modx/processors/security/profile/
11. I updated get.php from the above directory. After the section:
$profile = $user->getOne('Profile');
if ($profile) {
$userArray = array_merge($profile->toArray(),$userArray);
}
I added:
// Get the extended fields
$extended = $profile->get('extended');
if ($extended) {
foreach ($extended as $key => $value) {
$userArray[$key] = $value;
}
}
12. I updated update.php from the above directory, After the section:
/* save profile */
if ($profile->save() == false) {
return $modx->error->failure($modx->lexicon('user_profile_err_save'));
}
I added:
// Save the extended fields
if ($profile) {
$extended = $profile->get('extended');
if ($extended) {
foreach ($scriptProperties as $key => $value) {
if (strpos($key, 'ext_') !== false) {
$extended[$key] = $value;
}
}
$profile->set('extended', $extended);
$profile->save();
if ($profile->save() == false) {
return $modx->error->failure($modx->lexicon('user_profile_err_save'));
}
}
}[/code
]
So that's "all." I still think there has to be an easier way to do this. Notes on the above:
- There may be typos, feel free to point them out. I've been working on this for hours and my brain is fried.
- I may have left something out, feel free to point it out, or ask questions if you try it and it doesn't work. See above about brain fried.
- I realize this LONG post and mess of code may not belong in this particular forum, but I've been hacking MODx Revo like crazy recently and none of my last four questions have gotten any responses, so either I'm one of a very few people neck-deep in this code, or I'm posting in the wrong place. I at least wanted some kind of answer posted in case anyone needs to do this in the future. Mods, please feel free to move this... wherever.
- I'd love to actually make this an add-on, although since adding fields requires editing the update.js file, it's not as useful as it could be...
- After I've gone through all of this, please no one tell me there IS an add-on that I somehow missed that does exactly this. That may destroy the little bit of the sanity that I have left. ;-)
[ed. note: swd_cb02 last edited this post 15 years, 2 months ago.]