Skip to content

Instantly share code, notes, and snippets.

@pepebe
Last active May 2, 2022 12:27
Show Gist options
  • Save pepebe/20a6b971892a4071be80410b42f2d369 to your computer and use it in GitHub Desktop.
Save pepebe/20a6b971892a4071be80410b42f2d369 to your computer and use it in GitHub Desktop.
Add createdon and createdby to settings tab
<?php
/**
* Sample plugin to add a "createdby and createdon" field on a resource form
* Background: Issue #12305 "Adding createdon/createdby/publishedby/etc. to settings"
* https://github.com/modxcms/revolution/issues/12305
*
* Original author: rtripaul
* Original source: https://gist.github.com/rtripault/7306c8487a39fd1ce0db5f334c99be57
*
* @var modX $modx
* @var array $scriptProperties
*
* @event OnDocFormPrerender
*
* Warning: This plugin requires view_user permissions! Admins have them automatically. Your Editors might not have them.
*/
$dateFormat = $modx->getOption('manager_date_format',null,'d.m.Y');
$timeFormat = $modx->getOption('manager_time_format',null,'H:i');
$offset_time = (int) $modx->getOption('server_offset_time',null,0);
$manager_week_start = (int) $modx->getOption('manager_week_start',null,0);
$selector = "modx-page-settings-right"; // see manager customization for more containers
$selector = "modx-resource-main-right";
$modx->controller->addHtml("
<script>
// We are targeting the right column in the settings tab
Ext.ComponentMgr.onAvailable('".$selector."', function(right) {
right.on('beforerender', function() {
// page is a reference to the whole form panel
var page = Ext.getCmp('modx-panel-resource')
// record is a reference to our resource fields
,record = page.record
;
// How about a seperator?
right.add({
xtype : 'menuseparator',
width : '100%',
});
//right.add({ // Let's add our new field at the bottom of the column
right.insert(0,{ //either insert add the end of the container or a specific container.
xtype: 'xdatetime'
,fieldLabel: _('resource_createdon')
,description: '<b>[[*createdon]]</b><br>'+_('resource_createdon_help')
,name: 'createdon'
,id: 'modx-resource-createdon'
,allowBlank: false
,dateFormat: '".$dateFormat."'
,timeFormat: '".$timeFormat."'
,startDay: $manager_week_start
,dateWidth: 120
,timeWidth: 120
,offset_time: $offset_time
,value: record.createdon
,hiddenName: 'createdon'
});
// Let's add our new field at the bottom of the column
//right.add({
right.insert(0,{
xtype: 'modx-combo-user'
,name: 'createdby'
,hiddenName: 'createdby'
,value: record.createdby
,anchor: '100%'
,boxMaxWidth: 242
,layout: 'anchor'
,fieldLabel: _('resource_createdby')
});
})
});
</script>
"
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment