Set default author

The default author did not work, at least on my installation. I believe this is a better solution (although of course you can argue whether it should be getName() or FirstName).
This commit is contained in:
JorisDebonnet 2014-06-02 00:36:32 +02:00
parent 067003a6c3
commit 852b0cf440

View File

@ -44,19 +44,19 @@ class BlogEntry extends Page {
static $allow_wysiwyg_editing = true; static $allow_wysiwyg_editing = true;
/** /**
* Overload so that the default date is today. * Overload so that the default date is today and the default author is the logged in Member.
*/ */
public function populateDefaults(){ public function populateDefaults(){
parent::populateDefaults(); parent::populateDefaults();
$this->setField('Date', date('Y-m-d H:i:s', strtotime('now'))); $this->setField('Date', date('Y-m-d H:i:s', strtotime('now')));
$this->setField('Author', Member::currentUser() ? Member::currentUser()->getName() : '');
} }
function getCMSFields() { function getCMSFields() {
Requirements::javascript('blog/javascript/bbcodehelp.js'); Requirements::javascript('blog/javascript/bbcodehelp.js');
Requirements::themedCSS('bbcodehelp'); Requirements::themedCSS('bbcodehelp');
$firstName = Member::currentUser() ? Member::currentUser()->FirstName : '';
$codeparser = new BBCodeParser(); $codeparser = new BBCodeParser();
SiteTree::disableCMSFieldsExtensions(); SiteTree::disableCMSFieldsExtensions();
@ -71,7 +71,7 @@ class BlogEntry extends Page {
$fields->addFieldToTab("Root.Main", $dateField = new DatetimeField("Date", _t("BlogEntry.DT", "Date")),"Content"); $fields->addFieldToTab("Root.Main", $dateField = new DatetimeField("Date", _t("BlogEntry.DT", "Date")),"Content");
$dateField->getDateField()->setConfig('showcalendar', true); $dateField->getDateField()->setConfig('showcalendar', true);
$dateField->getTimeField()->setConfig('timeformat', 'H:m:s'); $dateField->getTimeField()->setConfig('timeformat', 'H:m:s');
$fields->addFieldToTab("Root.Main", new TextField("Author", _t("BlogEntry.AU", "Author"), $firstName),"Content"); $fields->addFieldToTab("Root.Main", new TextField("Author", _t("BlogEntry.AU", "Author")),"Content");
if(!self::$allow_wysiwyg_editing) { if(!self::$allow_wysiwyg_editing) {
$fields->addFieldToTab("Root.Main", new LiteralField("BBCodeHelper", "<div id='BBCode' class='field'>" . $fields->addFieldToTab("Root.Main", new LiteralField("BBCodeHelper", "<div id='BBCode' class='field'>" .