Class TreeDropdownField
Dropdown-like field that allows you to select an item from a hierachical AJAX-expandable tree.
Creates a field which opens a dropdown (actually a div via javascript included for you) which contains a tree with the ability to select a singular item for the value of the field. This field has the ability to store one-to-one joins related to hierarchy or a hierarchy based filter.
Note: your source object must use an implementation of hierarchy for this field to generate the tree correctly, e.g. groups, sitetree etc.
All operations are carried out through behaviour and javascript.
Usage.
treedropdownfield is used on VirtualPage a class which creates
another instance of a page, with exactly the same fields that can be represented
on another part of the site. The code below is taken from an example of
this.
// Put this at the top of the class that defines your model (e.g. the class that extends DataObject). static $has_one = array( 'RightContent' => 'SiteTree' ); // Setup the linking to the original page. (Put this in your getCMSFields() method or similar) $treedropdownfield = new TreeDropdownField("RightContentID", "Choose a page to show on the right:", "SiteTree");
This will generate a tree allowing the user to expand and contract subsections to find the appropriate page to save to the field.
- Object
-
ViewableData
implements
IteratorAggregate
-
RequestHandler
-
FormField
-
TreeDropdownField
Direct known subclasses
TreeDropdownField_Readonly,
TreeMultiselectField,
Widget_TreeDropdownField
Indirect known subclasses
See: TreeMultiselectField for the same implementation allowing multiple selections
See: DropdownField for a simple <select> field with a single element.
See: CheckboxSetField for multiple selections through checkboxes.
See: OptionsetField for single selections via radiobuttons.
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. |
public
|
#
setTreeBaseID( integer $ID )
Set the ID of the root node of the tree. This defaults to 0 - i.e. displays the whole tree. |
public
|
#
setFilterFunction( callable $callback )
Set a callback used to filter the values of the tree before displaying to the user. |
public
|
#
setSearchFunction( callable $callback )
Set a callback used to search the hierarchy globally, even before applying the filter. |
public
string
|
|
public
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. |
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. |
protected
|
#
objectForKey( string|integer $key )
Get the object where the $keyField is equal to a certain value |
public
|
Methods inherited from FormField
FieldHolder(),
LeftTitle(),
Link(),
Message(),
MessageType(),
Name(),
Required(),
RightTitle(),
SmallFieldHolder(),
Title(),
Type(),
Value(),
addExtraClass(),
attrName(),
attrTitle(),
attrValue(),
createTag(),
dataValue(),
debug(),
describe(),
extraClass(),
forTemplate(),
getCustomValidationMessage(),
getForm(),
getTabIndex(),
getTabIndexHTML(),
hasClass(),
hasData(),
id(),
isComposite(),
isDisabled(),
isReadonly(),
jsValidation(),
name_to_label(),
performDisabledTransformation(),
removeExtraClass(),
rootFieldSet(),
saveInto(),
securityTokenEnabled(),
setContainerFieldSet(),
setCustomValidationMessage(),
setDisabled(),
setError(),
setForm(),
setLeftTitle(),
setName(),
setReadonly(),
setRightTitle(),
setTabIndex(),
setTitle(),
setValue(),
transform(),
validate()
Methods inherited from RequestHandler
allowedActions(),
checkAccessAction(),
getRequest(),
handleRequest(),
hasAction(),
httpError()
Methods inherited from ViewableData
ATT_val(),
BaseHref(),
CSSClasses(),
CurrentMember(),
CurrentPage(),
Debug(),
Even(),
EvenOdd(),
First(),
FirstLast(),
HasPerm(),
IsAjax(),
JS_val(),
Last(),
Me(),
Middle(),
MiddleString(),
Modulus(),
MultipleOf(),
Odd(),
Pos(),
RAW_val(),
SQL_val(),
ThemeDir(),
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(),
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. |
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: |
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 |
protected
array
|
$searchExpanded |
Properties inherited from FormField
$containerFieldSet,
$customValidationMessage,
$description,
$disabled,
$dontEscape,
$extraClass,
$extraClasses,
$form,
$leftTitle,
$message,
$messageType,
$name,
$readonly,
$rightTitle,
$tabIndex,
$title,
$value
Properties inherited from RequestHandler
Properties inherited from ViewableData
$casting,
$customisedObject,
$default_cast,
$failover,
$iteratorPos,
$iteratorTotalItems
Comments
Use the Silverstripe Forum to ask questions.