Is there a way to create non static default values. Usually all default values are defined in $default array like:
static $defaults = array(
'Live' => true
);
I want to assign the ID of the member who created a news article page. For this purpose I created a relation like:
public static $has_one = array(
'Author' => 'Member'
);
This will create a new AuthorID in my NewsArticle related database table.
Each time a registered user creates a new NewsArticle, a DropDownField on CMS page should be displayed with preselected own Member (Member::currentUserID()) name. The user/news administrator should be able to change the member who created the specified news article.
The problem is, how can I pre select that member in the created DropDownList? What I tried so far is following:
[...]
$members = DataObject::get('Member');
if ($members) {
$membersmap = $members->map_multiple("ID", array("FirstName", "Surname"));
} else {
$membersmap = null;
}
$authorfield = new DropdownField('AuthorID', 'Author', $membersmap, Member::currentUserID());
$fields->addFieldToTab('Root.Content.Main', $authorfield, 'Content');
As I found out, the 4th argument in DropDownField ctor is the default value. But if a new news article page is created this 4th argument will be ignored, is always reset to 0. What can I do here to pre select a specified entry in DropDownField?
Even $authorfield->value = Member::currentUserID() didn't work. Is there maybe a bug in SilverStripe?
I'm using SilverStripe 2.3.4.
Thank's for help,
bkausbk