Skip to content

Instantly share code, notes, and snippets.

@matdave
Created August 12, 2020 21:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save matdave/178d52ac8c8cd114613444c005b42cb8 to your computer and use it in GitHub Desktop.
Save matdave/178d52ac8c8cd114613444c005b42cb8 to your computer and use it in GitHub Desktop.
MODX change author plugin
<?php
/**
* Plugin to add a "created by" field on a resource form and moves "published on" to document tab
*
* @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
,publishedon = Ext.getCmp('modx-resource-publishedon');
;
// Remove old published on
publishedon.destroy();
// Add created by
right.insert(0,{
xtype: 'modx-combo-user'
,name: 'createdby'
,hiddenName: 'createdby'
,value: record.createdby
,anchor: '100%'
,layout: 'anchor'
,fieldLabel: _('resource_createdby')
});
})
});
// We are targeting the right column in the resource tab
Ext.ComponentMgr.onAvailable('modx-resource-main-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
;
// Add new published on
right.insert(4,{
xtype: 'xdatetime'
,dateFormat:'".$dateFormat."'
,timeFormat:'".$timeFormat."'
,name: 'publishedon'
,hiddenName: 'publishedon'
,value: record.publishedon
,anchor: '100%'
,layout: 'anchor'
,fieldLabel: _('resource_publishedon')
});
})
});
</script>");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment