Version: current

     1 <?php
     2 /**
     3  * Description of SubsiteDropdownField
     4  *
     5  * @author inxo
     6  */
     7 class SubsiteDropdownField extends DropdownField {
     8     /**
     9      * Creates a new subsite dropdown field.
    10      * @param $name The field name
    11      * @param $title The field title
    12      */
    13     function __construct($name, $title = null, $value = false) {
    14         $source = array();
    15         $list = DataObject::get('Subsite', '"IsPublic"=1');
    16         $source = $list->toDropdownMap('ID', 'Title');
    17         if ($value === false) {
    18             $value = 0;
    19             foreach ($list as $item) {
    20                 if($item->DefaultSite){
    21                    $value = $item->ID;
    22                 }
    23             }
    24         }
    25         if (!DataObject::get_one('Subsite','"DefaultSite"=1 AND "IsPublic"=1')) {
    26             $source['00'] = 'Main site';
    27         }
    28         parent::__construct($name, ($title===null) ? $name : $title, $source, $value);
    29     }
    30 }
    31 ?>
    32

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -