backboneit / contao-selectri
A selection widget for large structured option sets.
Installs: 1 363
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 3
Language:HTML
Type:contao-module
pkg:composer/backboneit/contao-selectri
Requires
- php: >=5.2
- contao/core: >=2.11,<4
README
A selection widget for large structured option sets.
Usage in DCA
Input type token: selectri
eval Parameters
Value retrieval
The widgets canonical representation of selection values are arrays that map
selected nodes' keys to arrays containing the selected nodes' key at the array
key _key as well as additional data associated with this selected node.
If you work with the widget directly, it is strongly recommended that you use the getValue/setValue methods, which will always return values in this canonical representation form.
If you however use this widget in DCAs, it is desired that the widget's value
property (which is used by the DCA) is converted to - on retrieval - or
converted from - on set - a specific format. To avoid the registration of
load/save callbacks, the value property maintains an array of selected
options' keys or, if max is set to 1, a single selected option's key. For
commonly used conversions there exist the following eval properties to further
modify the value's property content:
-
findInSet- boolean - defaults tofalse-
get: Returns a comma-separated list of the selected options' keys. This behavior takes precedence over the
canonicalsetting. -
set: Strings are handled as comma-separated lists of selected options' keys and gets split at
,. A normalization to the canonical form is done after.
-
-
canonical- boolean - defaults tofalse-
get: Returns the canonical form of the selection or, if
maxis set to1, only the selected option's data array. -
set: A normalization to the canonical form is done.
-
Basic widget configuration
-
min- integer, non-negative - defaults to0How many nodes must be selected at least.
If the
maxparameter is less than the configured minimum, theminparameter will be considered equal to the configured maximum. -
max- integer, positive - defaults to1How many nodes can be selected at most.
-
mandatory- boolean - optional - deprecated: theminparameter should be usedIf given and
true, theminparameter will be set to1, if it is not> 0already. If given andfalse, theminparameter will be set to0. -
multiple- boolean - optional - deprecated: themaxparameter should be usedIf given and
true, themaxparameter will be set toPHP_INT_MAX, if it is not> 1already. If given andfalse, themaxparameter will be set to1. -
searchLimit- integer, positive - defaults to20The max nodes retrieved from searches.
-
sort- string, one oflist,preorder,tree- defaults tolistThe structure implied on the made selection
list: the selection is a list (order matters), the selection is sortablepreordernot implemented: the selection is a set (order does not matter), the selection is not sortable and preorderedtreenot implemented: the selection is a tree, the selection can be arranged with tree properties
-
height- string - defaults toautoThe CSS value and unit of the CSS
heightproperty of the selection tree. -
tl_class- string - optionalOnly used in Backend.
-
class- string - optionalUse this to apply your custom CSS savely. You can use "radio" or "checkbox" to replace the Contao-style select (+) and deselect (x) icons with Windows legacy input-like icon images.
-
data- string or an object implementingSelectriDataFactory- defaults to the stringSelectriContaoTableDataFactoryIf a factory object is given, these factory will be used to generate a data instance for created widgets. The
setParametersmethod is not called. This is the recommended way to provide aSelectriData, as all data implementation specific features and options can be properly configured through their factories.If a string is given, it must name a class implementing
SelectriDataFactory. When creating the widget, a new factory instance is created and itssetParametersmethod is called with the attributes of the widget (the widget's attributes contains all settings from the DCA'sevalarray).
Factory specific configuration (used by setParameters method of the
SelectriDataFactory class given in the data parameter)
-
treeTable- string - optionalThe name of the table to fetch tree nodes from.
The parameter is used by
SelectriContaoTableDataFactory::setParametersmethod and preconfigures the data according to common Contao standards like primary key columnidand parent key columnpid. -
mode- string - defaults toallThe parameter is used by
SelectriTableDataFactory::setParametersmethod.all: all nodes are selectableleaf: only leaf nodes are selectableinner: only inner nodes are selectable
Simple example for usage in DCA
$GLOBALS['TL_DCA']['tl_mydca']['fields']['mySelectriField'] = array( ... 'inputType' => 'selectri', ... 'eval' => array( // all values are the defaults 'min' => 0, // the selection can be empty 'max' => 1, // let the user select not more than 1 item 'searchLimit' => 20, // max search results 'findInSet' => false, // dont use csv 'additionalInput' => false, // no additional inputs via node content callback is injected 'sort' => 'list', 'height' => 'auto', // the height of the tree widget 'tl_class' => 'clr', // some css-classes, 'class' => '', // use "radio" or "checkbox" to replace the icons 'data' => 'SelectriContaoTableDataFactory', // the data factory class to use 'treeTable' => 'tl_page', // a DB-table containing the tree structure (Contao-like adjacency list) 'mode' => 'all', // which nodes are selectable: "all", "leaf", "inner" ), ... );
Advanced example for usage in DCA
Instead of using a implicit created factory instance by providing a factory
class name in the previous example, you can preconfigure your own factory
instance and have full access to all parameters used by the SelectriData-class
produced by the factory.
$data = SelectriContaoTableDataFactory::create(); // use the tl_page table for the tree structure $data->setTreeTable('tl_page'); // show all nodes $data->getConfig()->setTreeMode('all'); // search the title and pageTitle column $data->getConfig()->setTreeSearchColumns(array('title', 'pageTitle')); // only show nodes matching the condition $data->getConfig()->setTreeConditionExpr('type = \'regular\' AND tstamp > 0'); // only let the user select nodes matching the condition $data->getConfig()->setSelectableExpr('hide <> \'1\''); // for more parameters see the factory class and the underlaying config class $GLOBALS['TL_DCA']['tl_mydca']['fields']['mySelectriField'] = array( ... 'inputType' => 'selectri', ... 'eval' => array( 'min' => 0, 'max' => 1, 'searchLimit' => 20, 'tl_class' => 'clr', 'class' => 'checkbox', // assign your preconfigured factory instance to the widgets configuration 'data' => $data, ), ... );