I have a dropdown field available on all page types throughout my site in Page.php which allows the user to specify which sites can see that content.
For some reason when a site is selected from the dropdown list; the ID is sent in the response but the value is not stored in the SiteID column for that article...
Page.php
class Page extends SiteTree {
# ...
private static $has_one = array(
'Site' => 'Site'
);
public function getSettingsFields(){
$fields = parent::getSettingsFields();
$sites = new DropdownField('Site', 'Select a site that will see this article', Site::getListOfSites());
$sites->setEmptyString('All');
$fields->addFieldToTab('Root.Settings', $sites);
return $fields;
}
# ...
}
Site.php
class Site extends DataObject {
private static $db = array(
'Title' => 'Varchar(255)',
'Code' => 'Varchar(20)',
'TimeZone' => 'Varchar(20)' // UTC+0:00, UTC-7:00
);
private static $has_one = array(
);
private static $has_many = array(
'Pages' => 'Page'
);
public function getListOfSites(){
if($sites = DataObject::get('Site'))
return $sites->map('ID', 'Title');
}
# ...
What do I need in order for it to store the relevant ID to the pages SiteID column?..