Webylon 3.1 API Docs
  • Package
  • Class
  • Tree
  • Deprecated
  • Download
Version: current
  • 3.2
  • 3.1

Packages

  • auth
  • Booking
  • cart
    • shipping
    • steppedcheckout
  • Catalog
  • cms
    • assets
    • batchaction
    • batchactions
    • bulkloading
    • comments
    • content
    • core
    • export
    • newsletter
    • publishers
    • reports
    • security
    • tasks
  • Dashboard
  • DataObjectManager
  • event
  • faq
  • forms
    • actions
    • core
    • fields-basic
    • fields-dataless
    • fields-datetime
    • fields-files
    • fields-formatted
    • fields-formattedinput
    • fields-relational
    • fields-structural
    • transformations
    • validators
  • googlesitemaps
  • guestbook
  • installer
  • newsletter
  • None
  • photo
    • gallery
  • PHP
  • polls
  • recaptcha
  • sapphire
    • api
    • bulkloading
    • control
    • core
    • cron
    • dev
    • email
    • fields-formattedinput
    • filesystem
    • formatters
    • forms
    • i18n
    • integration
    • misc
    • model
    • parsers
    • search
    • security
    • tasks
    • testing
    • tools
    • validation
    • view
    • widgets
  • seo
    • open
      • graph
  • sfDateTimePlugin
  • spamprotection
  • stealth
    • captha
  • subsites
  • userform
    • pagetypes
  • userforms
  • webylon
  • widgets

Classes

  • HTMLDropdownField
  • SimpleTreeDropdownField
 1 <?php
 2 
 3 class SimpleTreeDropdownField extends HTMLDropdownField
 4 {
 5     protected $sourceClass;
 6     protected $labelField;
 7     
 8     function __construct($name, $title = "", $sourceClass = "SiteTree", $value = "", $labelField = "Title", $form = null, $emptyString = null)
 9     {
10         $this->sourceClass = $sourceClass;
11         $this->labelField = $labelField;
12         parent::__construct($name, $title, $this->getHierarchy(0), $value, $form, $emptyString);
13     }
14     
15     public function setLabelField($field)
16     {
17         $this->labelField = $field;
18     }
19     
20     private function getHierarchy($parentID, $level = 0)
21     {
22         $options = array();     
23         if($children = DataObject::get($this->sourceClass, "ParentID = $parentID")) {
24             foreach($children as $child) {
25                 $indent="";
26                 for($i=0;$i<$level;$i++) $indent .= "&nbsp;&nbsp;";
27                 $text = $child->__get($this->labelField);
28                 $options[$child->ID] = empty($text) ? "<em>$indent Untitled</em>" : $indent.$text;
29                 $options += $this->getHierarchy($child->ID, $level+1);
30             }
31         }
32         return $options;    
33     }
34 }
35 
[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. -
Webylon 3.1 API Docs API documentation generated by ApiGen 2.8.0