Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Blog Module /

Discuss the Blog Module.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Remove Author Field


Go to End


12 Posts   4345 Views

Avatar
Mo

Community Member, 541 Posts

27 June 2011 at 5:24am

Unfortunately not! I have tried a few different approaches and all of them have proven in-effective.

Looking at the source code, it looks like the BlogEntry class is supposed to have the current logged in user pre-populated in the Author field, but for some reason that doesn't seem to work.

The only other thing I could think that you could do would be to generate a dropdown of all members (possibly filtered by a group, say 'blog-editors') and replace the existing author field with that.

Mo

Avatar
mierla

Community Member, 16 Posts

27 June 2011 at 5:27am

Hey... that's a thought. I think I'll give that a shot - thanks!

Avatar
mierla

Community Member, 16 Posts

27 June 2011 at 6:30am

It worked! (I think; haven't tested front-end editing yet)
I edited BlogEntry directly, which I know is a no-no. Now that I've got it working, I may try to go back to stock there and properly extend the BlogEntry class.

So here's what I did:

I removed Author from the db array, and added it as a has_one, then added this to the getCMSFields function:

$fields->addFieldToTab("Root.Content.Main", new DropdownField('AuthorID', 'Please choose an author', Dataobject::get("Member")->map("ID", "FullName", $fullName)), "Content");                

It *seems* to be working. I added a getComponent function, and now I can call all the Member fields from my template. Hooray! Thank you!

Avatar
webmanj

Community Member, 7 Posts

1 February 2012 at 11:48pm

Hello all,

I'm a little late to the game but I do have a solution if no one has one that really works. Here's what you do:

public function populateDefaults(){
parent::populateDefaults();
$this->setField('Date', date('Y-m-d H:i:s', strtotime('now')));
$this->Author = Member::currentUser() ? Member::currentUser()->FirstName : '';
}

Then, comment out OR remove/replace the following entries from getCMSFields

//$firstName = Member::currentUser() ? Member::currentUser()->FirstName : '';
//$fields->addFieldToTab("Root.Content.Main", new TextField("Author", _t("BlogEntry.AU", "Author"), $firstName),"Content");
$fields->addFieldToTab("Root.Content.Main", new TextField("Author", _t("BlogEntry.AU", "Author")),"Content");

This has worked 100% of the time and I believe is the correct way to do it.

Hope this helps someone.

Thanks,
Jason

Go to Top