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

Packages

  • cms
    • assets
    • batchaction
    • batchactions
    • content
    • control
    • controller
    • controllers
    • core
    • export
    • filesystem
    • forms
    • model
    • publishers
    • reports
    • search
    • security
    • tasks
  • forms
    • actions
    • core
    • fields-basic
    • fields-dataless
    • fields-datetime
    • fields-files
    • fields-formattedinput
    • fields-relational
    • fields-structural
    • transformations
    • validators
  • framework
    • admin
    • bulkloading
    • control
    • core
    • cron
    • dev
    • email
    • fields-formattedinput
    • fields-relational
    • filesystem
    • formatters
    • forms
    • gridfield
    • i18n
    • injector
    • integration
    • manifest
    • misc
    • model
    • parsers
    • search
    • security
    • tasks
    • testing
    • validation
    • view
  • None
  • PHP

Classes

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

Class TreeMultiselectField

This formfield represents many-many joins using a tree selector shown in a dropdown styled element which can be added to any form usually in the CMS.

This form class allows you to represent Many-Many Joins in a handy single field. The field has javascript which generates a AJAX tree of the site structure allowing you to save selected options to a component set on a given DataObject.

Saving

This field saves a ComponentSet object which is present on the DataObject passed by the form, returned by calling a function with the same name as the field. The Join is updated by running setByIDList on the ComponentSet

Customizing Save Behaviour

Before the data is saved, you can modify the ID list sent to the ComponentSet by specifying a function on the DataObject called "onChange[fieldname](&items)". This will be passed by reference the IDlist (an array of ID's) from the Treefield to be saved to the component set.

Returning false on this method will prevent treemultiselect from saving to the ComponentSet of the given DataObject

// Called when we try and set the Parents() component set
// by Tree Multiselect Field in the administration.
function onChangeParents(&$items) {
 // This ensures this DataObject can never be a parent of itself
        if($items){
                foreach($items as $k => $id){
                        if($id == $this->ID){
                                unset($items[$k]);
                        }
                }
        }
        return true;
}
Object
Extended by ViewableData implements IteratorAggregate
Extended by RequestHandler
Extended by FormField
Extended by TreeDropdownField
Extended by TreeMultiselectField

Direct known subclasses

TreeMultiselectField_Readonly

Package: forms\fields-relational
See: TreeDropdownField for the sample implementation, but only allowing single selects
Located at sapphire/forms/TreeMultiselectField.php

Methods summary

public
# __construct( string $name, string $title = null, sourceObject $sourceObject = "Group", string $keyField = "ID", string $labelField = "Title" )

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 Hierarchy subclass. Alternatively, you can set this to an array of key/value pairs, like a DropdownField source. In this case, the field will act like show a flat list of tree items, without any hierarchy. 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).

Overrides

TreeDropdownField::__construct
public
# getItems( )

Return this field's linked items

Return this field's linked items

public string
# Field( array $properties = array() )

We overwrite the field attribute to add our hidden fields, as this formfield can contain multiple values.

We overwrite the field attribute to add our hidden fields, as this formfield can contain multiple values.

Parameters

$properties
array
$properties key value pairs of template variables

Returns

string

Overrides

TreeDropdownField::Field
public
# saveInto( DataObjectInterface $record )

Save the results into the form Calls function $record->onChange($items) before saving to the assummed Component set.

Save the results into the form Calls function $record->onChange($items) before saving to the assummed Component set.

Overrides

FormField::saveInto
public
# performReadonlyTransformation( )

Changes this field to the readonly field.

Changes this field to the readonly field.

Overrides

TreeDropdownField::performReadonlyTransformation

Methods inherited from TreeDropdownField

extraClass(), filterMarking(), getShowSearch(), objectForKey(), populateIDs(), setChildrenMethod(), setFilterFunction(), setSearchFunction(), setShowSearch(), setTreeBaseID(), tree()

Methods inherited from FormField

FieldHolder(), ID(), LeftTitle(), Link(), Message(), MessageType(), Name(), Required(), RightTitle(), SmallFieldHolder(), Title(), Type(), Value(), addExtraClass(), attrTitle(), attrValue(), createTag(), dataValue(), debug(), describe(), forTemplate(), getAttribute(), getAttributes(), getAttributesHTML(), getCustomValidationMessage(), getDescription(), getFieldHolderTemplate(), getFieldHolderTemplates(), getForm(), getName(), getSmallFieldHolderTemplate(), getSmallFieldHolderTemplates(), getTabIndex(), getTemplate(), getTemplates(), hasClass(), hasData(), isComposite(), isDisabled(), isReadonly(), name_to_label(), performDisabledTransformation(), removeExtraClass(), rootFieldList(), rootFieldSet(), securityTokenEnabled(), setAttribute(), setContainerFieldList(), setContainerFieldSet(), setCustomValidationMessage(), setDescription(), setDisabled(), setError(), setFieldHolderTemplate(), setForm(), setLeftTitle(), setName(), setReadonly(), setRightTitle(), setSmallFieldHolderTemplate(), setTabIndex(), setTemplate(), setTitle(), setValue(), transform(), validate()

Methods inherited from RequestHandler

allowedActions(), checkAccessAction(), getRequest(), handleRequest(), hasAction(), httpError(), isAjax(), setDataModel(), setRequest()

Methods inherited from ViewableData

ATT_val(), CSSClasses(), Debug(), JS_val(), Me(), RAW_val(), SQL_val(), ThemeDir(), XML_val(), __get(), __isset(), __set(), buildCastingCache(), cachedCall(), castingClass(), castingHelper(), castingHelperPair(), castingObjectCreator(), castingObjectCreatorPair(), customise(), defineMethods(), escapeTypeForField(), getField(), getIterator(), getXMLValues(), hasField(), hasValue(), obj(), renderWith(), setCustomisedObj(), setField()

Methods inherited from Object

__call(), __toString(), addMethodsFrom(), addStaticVars(), addWrapperMethod(), add_extension(), add_static_var(), allMethodNames(), cacheToFile(), clearCache(), combined_static(), config(), create(), createMethod(), create_from_string(), exists(), extend(), getCustomClass(), getExtensionInstance(), getExtensionInstances(), get_extensions(), get_extra_config_sources(), 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(), static_lookup(), strong_create(), uninherited(), uninherited_static(), useCustomClass()

Magic methods summary

Properties summary

Properties inherited from TreeDropdownField

$allowed_actions, $baseID, $childrenMethod, $filterCallback, $keyField, $labelField, $searchCallback, $searchExpanded, $searchIds, $showSearch, $url_handlers

Properties inherited from FormField

$attributes, $containerFieldList, $customValidationMessage, $description, $disabled, $dontEscape, $extraClass, $extraClasses, $fieldHolderTemplate, $form, $leftTitle, $message, $messageType, $name, $readonly, $rightTitle, $smallFieldHolderTemplate, $template, $title, $value

Properties inherited from RequestHandler

$brokenOnConstruct, $model, $request

Properties inherited from ViewableData

$casting, $customisedObject, $default_cast, $failover

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 3.0 API Docs API documentation generated by ApiGen 2.8.0