Version: current

# Class TreeDropdownField

Dropdown-like field that allows you to select an item from a hierachical AJAX-expandable tree

  Object
  ViewableData implements IteratorAggregate
  RequestHandler
  FormField
  TreeDropdownField

### Direct known subclasses

`OrderItemField`, `SubsitesTreeDropdownField`, `TreeDropdownField_Readonly`, `TreeMultiselectField`, `Widget_TreeDropdownField`

### Indirect known subclasses

`TreeMultiselectField_Readonly`

Package: forms\fields-relational
Located at sapphire/forms/TreeDropdownField.php

## Methods summary

`public` | # `__construct( string $name, string $title = null, sourceObject $sourceObject = 'Group', string $keyField = 'ID', string $labelField = 'Title', string $showSearch = false )` CAVEAT: for search to work properly $labelField must be a database field, or you need to setSearchFunction. CAVEAT: for search to work properly $labelField must be a database field, or you need to setSearchFunction. #### Parameters $name string $name the field name $title string $title the field label $sourceObject sourceObject The object-type to list in the tree. Must be a 'hierachy' object. Alternatively, you can set this to an array of key/value pairs, like a dropdown source. In this case, the field will act like show a flat list of tree items, without any hierachy. This is most useful in conjunction with TreeMultiselectField, for presenting a set of checkboxes in a compact view. $keyField string $keyField to field on the source class to save as the field value (default ID). $labelField string $labelField the field name to show as the human-readable value on the tree (default Title). $showSearch string $showSearch enable the ability to search the tree by entering the text in the input field. #### Overrides `FormField::__construct`
`public` | # `setTreeBaseID( integer $ID )` Set the ID of the root node of the tree. This defaults to 0 - i.e. displays the whole tree. Set the ID of the root node of the tree. This defaults to 0 - i.e. displays the whole tree. #### Parameters $ID int $ID
`public` | # `setFilterFunction( callable $callback )` Set a callback used to filter the values of the tree before displaying to the user. Set a callback used to filter the values of the tree before displaying to the user. #### Parameters $callback callback $callback
`public` | # `setSearchFunction( callable $callback )` Set a callback used to search the hierarchy globally, even before applying the filter. Set a callback used to search the hierarchy globally, even before applying the filter. #### Parameters $callback callback $callback
`public string` | # `Field( )` #### Returns `string` string #### Overrides `FormField::Field`
`public string` | # `tree( `SS_HTTPRequest` $request )` Get the whole tree of a part of the tree via an AJAX request. Get the whole tree of a part of the tree via an AJAX request. #### Parameters $request SS_HTTPRequest $request #### Returns `string` string
`public unknown_type` | # `filterMarking( mixed $node )` Marking function for the tree, which combines different filters sensibly. If a filter function has been set, that will be called. If the source is a folder, automatically filter folder. And if search text is set, filter on that too. Return true if all applicable conditions are true, false otherwise. Marking function for the tree, which combines different filters sensibly. If a filter function has been set, that will be called. If the source is a folder, automatically filter folder. And if search text is set, filter on that too. Return true if all applicable conditions are true, false otherwise. #### Parameters $node $node #### Returns `unknown_type` unknown_type
`protected` | # `populateIDs( )` Populate $this->searchIds with the IDs of the pages matching the searched parameter and their parents. Reverse-constructs the tree starting from the leaves. Initially taken from CMSSiteTreeFilter, but modified with pluggable search function. Populate $this->searchIds with the IDs of the pages matching the searched parameter and their parents. Reverse-constructs the tree starting from the leaves. Initially taken from CMSSiteTreeFilter, but modified with pluggable search function.
`protected `DataObject`` | # `objectForKey( string|integer $key )` Get the object where the $keyField is equal to a certain value Get the object where the $keyField is equal to a certain value #### Parameters $key string|int $key #### Returns ``DataObject`` DataObject
`public` | # `performReadonlyTransformation( )` Changes this field to the readonly field. Changes this field to the readonly field. #### Overrides `FormField::performReadonlyTransformation`

### Methods inherited from FormField

`FieldHolder()`, `LeftTitle()`, `Link()`, `Message()`, `MessageType()`, `Name()`, `Required()`, `RightTitle()`, `SmallFieldHolder()`, `Title()`, `Type()`, `Value()`, `addExtraAttribute()`, `addExtraClass()`, `allowHTML5()`, `allow_html5()`, `attrName()`, `attrTitle()`, `attrValue()`, `createTag()`, `dataValue()`, `debug()`, `describe()`, `extraClass()`, `fieldHolderTemplates()`, `fieldTemplates()`, `forTemplate()`, `getCustomValidationMessage()`, `getExtraClasses()`, `getForm()`, `getHTML5Attribute()`, `getTabIndex()`, `getTabIndexHTML()`, `hasClass()`, `hasData()`, `id()`, `isComposite()`, `isDisabled()`, `isReadonly()`, `jsValidation()`, `name_to_label()`, `performDisabledTransformation()`, `removeExtraAttribute()`, `removeExtraClass()`, `rootFieldSet()`, `saveInto()`, `securityTokenEnabled()`, `setAutocomplete()`, `setContainerFieldSet()`, `setCustomValidationMessage()`, `setDisabled()`, `setError()`, `setFieldHolderTemplate()`, `setForm()`, `setHTML5Attribute()`, `setLeftTitle()`, `setName()`, `setReadonly()`, `setRightTitle()`, `setSmallFieldHolderTemplate()`, `setTabIndex()`, `setTemplate()`, `setTitle()`, `setValue()`, `smallFieldHolderTemplates()`, `transform()`, `useHTML5()`, `use_html5()`, `validate()`

### Methods inherited from RequestHandler

`allowedActions()`, `checkAccessAction()`, `getRequest()`, `handleRequest()`, `hasAction()`, `httpError()`

### Methods inherited from ViewableData

`ATT_val()`, `BaseHref()`, `CSSClasses()`, `ColumnBreak()`, `ColumnCalc()`, `ColumnNumber()`, `ColumnPad()`, `ColumnPos()`, `CurrentMember()`, `CurrentPage()`, `Debug()`, `Even()`, `EvenOdd()`, `First()`, `FirstLast()`, `HasPerm()`, `IsAjax()`, `JS_val()`, `Last()`, `Me()`, `Middle()`, `MiddleString()`, `Modulus()`, `MultipleOf()`, `Odd()`, `Pos()`, `RAW_val()`, `SQL_val()`, `ThemeDir()`, `ThemeName()`, `Top()`, `TotalItems()`, `XML_val()`, `__get()`, `__isset()`, `__set()`, `buildCastingCache()`, `cachedCall()`, `castingClass()`, `castingHelper()`, `castingHelperPair()`, `castingObjectCreator()`, `castingObjectCreatorPair()`, `customise()`, `defineMethods()`, `escapeTypeForField()`, `getField()`, `getIterator()`, `getSecurityID()`, `getXMLValues()`, `hasField()`, `hasValue()`, `i18nLocale()`, `iteratorProperties()`, `obj()`, `renderWith()`, `setCustomisedObj()`, `setField()`

### Methods inherited from Object

`__call()`, `__toString()`, `__wakeup()`, `addMethodsFrom()`, `addStaticVars()`, `addWrapperMethod()`, `add_extension()`, `add_static_var()`, `allMethodNames()`, `cacheToFile()`, `cacheToFileWithArgs()`, `clearCache()`, `combined_static()`, `create()`, `createMethod()`, `create_from_string()`, `exists()`, `extInstance()`, `extend()`, `getCustomClass()`, `getExtensionInstance()`, `getExtensionInstances()`, `get_extensions()`, `get_static()`, `hasExtension()`, `hasMethod()`, `has_extension()`, `invokeWithExtensions()`, `is_a()`, `loadCache()`, `parentClass()`, `parse_class_spec()`, `remove_extension()`, `sanitiseCachename()`, `saveCache()`, `set_stat()`, `set_static()`, `set_uninherited()`, `stat()`, `strong_create()`, `uninherited()`, `uninherited_static()`, `useCustomClass()`

### Magic methods summary

## Properties summary

`public static array` | $url_handlers | # The default URL handling rules. This specifies that the next component of the URL corresponds to a method to be called on this RequestHandlingData object. The default URL handling rules. This specifies that the next component of the URL corresponds to a method to be called on this RequestHandlingData object. The keys of this array are parse rules. See `SS_HTTPRequest::match()` for a description of the rules available. The values of the array are the method to be called if the rule matches. If this value starts with a '$', then the named parameter of the parsed URL wil be used to determine the method name.
`public static array` | $allowed_actions | # Define a list of action handling methods that are allowed to be called directly by URLs. The variable should be an array of action names. This sample shows the different values that it can contain: Define a list of action handling methods that are allowed to be called directly by URLs. The variable should be an array of action names. This sample shows the different values that it can contain:
    array(
            'someaction', // someaction can be accessed by anyone, any time
            'otheraction' => true, // So can otheraction
            'restrictedaction' => 'ADMIN', // restrictedaction can only be people with ADMIN privilege
            'complexaction' '->canComplexAction' // complexaction can only be accessed if $this->canComplexAction() returns true
    );
`protected mixed` | $keyField | #
`protected mixed` | $labelField | #
`protected mixed` | $filterCallback | #
`protected mixed` | $searchCallback | #
`protected integer` | $baseID | #
`protected mixed` | $searchIds | # Used by field search to leave only the relevant entries Used by field search to leave only the relevant entries
`protected array` | $searchExpanded | #

### Properties inherited from FormField

`$autocomplete`, `$containerFieldSet`, `$customValidationMessage`, `$description`, `$disabled`, `$dontEscape`, `$extraAttributes`, `$extraClass`, `$extraClasses`, `$fieldHTML5`, `$fieldHolderTemplate`, `$form`, `$html5Attributes`, `$leftTitle`, `$message`, `$messageType`, `$name`, `$possible_autocomplete_values`, `$readonly`, `$rightTitle`, `$smallFieldHolderTemplate`, `$tabIndex`, `$template`, `$title`, `$use_html5`, `$value`

### Properties inherited from RequestHandler

`$brokenOnConstruct`, `$request`

### Properties inherited from ViewableData

`$casting`, `$customisedObject`, `$default_cast`, `$failover`, `$iteratorPos`, `$iteratorTotalItems`

### Properties inherited from Object

`$class`, `$extension_instances`, `$extensions`

[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. -