backboneit / contao-selectri
Requires
- php: >=5.2
- contao/core: >=2.11,<4
README
用于大型结构化选项集的选择小部件。
DCA中的使用
输入类型令牌: selectri
eval参数
值检索
小部件选择值的规范表示是数组,该数组将所选节点的键映射到包含所选节点键的数组,该键位于数组键 _key,以及与所选节点关联的附加数据。
如果您直接处理此小部件,强烈建议您使用 getValue/setValue 方法,这些方法始终以这种规范表示形式返回值。
但是,如果您在DCAs中使用此小部件,则希望小部件的 value 属性(由DCA使用)在检索时或设置时转换为特定的格式。为了避免注册加载/保存回调,value 属性维护一个选中选项的键数组,如果 max 设置为 1,则是一个选中的选项的键。对于常用的转换,存在以下eval属性来进一步修改value属性的内容
-
findInSet- 布尔型 - 默认为false-
获取:返回选中选项键的逗号分隔列表。此行为优先于
canonical设置。 -
设置:字符串被处理为选中选项键的逗号分隔列表,并在
,处分割。之后执行规范化。
-
-
canonical- 布尔型 - 默认为false-
获取:返回选择的规范形式或,如果
max设置为1,则只返回选中选项的数据数组。 -
设置:执行规范化。
-
基本小部件配置
-
min- 整数,非负 - 默认为0至少必须选择的节点数。
如果
max参数小于配置的最小值,则将min参数视为等于配置的最大值。 -
max- 整数,正数 - 默认为1最多可以选择的节点数。
-
mandatory- 布尔型 - 可选 - 已弃用:应使用min参数如果提供且为
true,则将min参数设置为1,如果它不是> 0,则已设置。如果提供且为false,则将min参数设置为0。 -
multiple- 布尔型 - 可选 - 已弃用:应使用max参数如果提供且为
true,则将max参数设置为PHP_INT_MAX,如果它不是> 1,则已设置。如果提供且为false,则将max参数设置为1。 -
searchLimit- 整数,正数 - 默认为20搜索中检索到的最大节点数。
-
sort- 字符串,其中之一为list、preorder、tree- 默认为list隐含在所做选择中的结构
list:选择的项为一个列表(顺序重要),可以选择排序。preorder未实现:选择的项为一个集合(顺序不重要),不能排序且预排序。tree未实现:选择的项为一个树,可以选择使用树属性进行排列。
-
height- 字符串 - 默认为auto选择树的CSS
height属性的值和单位。 -
tl_class- 字符串 - 可选仅在后端使用。
-
class- 字符串 - 可选用于安全地应用自定义CSS。您可以使用 "radio" 或 "checkbox" 替换Contao样式的选择(+)和取消选择(x)图标,以使用Windows传统输入图标图像。
-
data- 字符串或实现SelectriDataFactory的对象 - 默认为字符串SelectriContaoTableDataFactory如果提供了工厂 对象,则这些工厂将用于为创建的控件生成数据实例。不会调用
setParameters方法。这是提供SelectriData的推荐方式,因为所有数据实现特定功能和选项都可以通过它们的工厂进行适当配置。如果提供了字符串,它必须是指实现
SelectriDataFactory的类的名称。在创建控件时,将创建一个新的工厂实例,并使用控件的属性调用其setParameters方法(控件的属性包含DCA的eval数组中的所有设置)。
工厂特定配置(由 data 参数中给出的 SelectriDataFactory 类的 setParameters 方法使用)
-
treeTable- 字符串 - 可选要从中获取树节点的表名称。
该参数由
SelectriContaoTableDataFactory::setParameters方法使用,并根据常见的Contao标准预先配置数据,例如主键列id和父键列pid。 -
mode- 字符串 - 默认为all该参数由
SelectriTableDataFactory::setParameters方法使用。all:所有节点都可以选择leaf:只有叶节点可以选择inner:只有内部节点可以选择
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" ), ... );
DCA中使用的复杂示例
在上一示例中,不是通过提供工厂类名来使用隐式创建的工厂实例,而是可以预先配置自己的工厂实例,并完全访问由工厂产生的 SelectriData-类的所有参数。
$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, ), ... );