SilverStripe 2.4 API Docs
  • Package
  • Class
  • Tree
  • Deprecated
Version: master
  • master
  • 3.1
  • 3.0
  • 2.4
  • tagfield

Packages

  • cms
    • assets
    • batchaction
    • batchactions
    • bulkloading
    • comments
    • content
    • core
    • export
    • publishers
    • reports
    • security
    • tasks
  • forms
    • actions
    • core
    • fields-basic
    • fields-dataless
    • fields-datetime
    • fields-files
    • fields-formatted
    • fields-formattedinput
    • fields-relational
    • fields-structural
    • transformations
    • validators
  • installer
  • None
  • PHP
  • 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

Classes

  • ComplexTableField
  • ComplexTableField_Item
  • ComplexTableField_ItemRequest
  • ComplexTableField_Popup
  • CountryDropdownField
  • HasManyComplexTableField
  • HasManyComplexTableField_Item
  • HasOneComplexTableField
  • HasOneComplexTableField_Item
  • LanguageDropdownField
  • ManyManyComplexTableField
  • ManyManyComplexTableField_Item
  • ScaffoldingComplexTableField_Popup
  • TableField
  • TableField_Item
  • TableListField
  • TableListField_Item
  • TableListField_ItemRequest
  • TreeDropdownField
  • TreeDropdownField_Readonly
  • TreeMultiselectField
  • TreeMultiselectField_Readonly
  • TreeSelectorField

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
Extended by ViewableData implements IteratorAggregate
Extended by RequestHandler
Extended by FormField
Extended by TreeDropdownField

Direct known subclasses

TreeDropdownField_Readonly, TreeMultiselectField, Widget_TreeDropdownField

Indirect known subclasses

TreeMultiselectField_Readonly

Package: forms\fields-relational
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.

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
integer
$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
callable
$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
callable
$callback
public string
# Field( )

Returns

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
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
mixed
$node

Returns

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|integer
$key

Returns

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(), 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.

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
);

Form getters count as URL actions as well, and should be included in allowed_actions. Form actions on the other handed (first argument to FormAction() should NOT be included, these are handled separately through Form->httpSubmission. You can control access on form actions either by conditionally removing FormAction in the form construction, or by defining $allowed_actions in your Form class.

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

$containerFieldSet, $customValidationMessage, $description, $disabled, $dontEscape, $extraClass, $extraClasses, $form, $leftTitle, $message, $messageType, $name, $readonly, $rightTitle, $tabIndex, $title, $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

Comments

Comment policy: Please use comments for tips and corrections about the described functionality. Comments are moderated, we reserve the right to remove comments that are inappropriate or are no longer relevant.
Use the Silverstripe Forum to ask questions.
blog comments powered by Disqus
SilverStripe 2.4 API Docs API documentation generated by ApiGen 2.8.0