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
*/
$dateFormat = $modx->getOption('manager_date_format',null,'d.m.Y');
$timeFormat = $modx->getOption('manager_time_format',null,'H:i');
$modx->controller->addHtml("
<script>
// We are targeting the right column in the settings tab
Ext.ComponentMgr.onAvailable('modx-page-settings-right', 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
;
// Let's add our new field at the bottom of the column
right.add({
xtype: 'xdatetime'
,dateFormat:'".$dateFormat."'
,timeFormat:'".$timeFormat."'
,name: 'createdon'
,hiddenName: 'createdon'
,value: record.createdon
,anchor: '100%'
,layout: 'anchor'
,fieldLabel: _('resource_createdon')
});
// Let's add our new field at the bottom of the column
right.add({
xtype: 'modx-combo-user'
,name: 'createdby'
,hiddenName: 'createdby'
,value: record.createdby
,anchor: '100%'
,layout: 'anchor'
,fieldLabel: _('resource_createdby')
});
})
});
</script>
"
);