oveleon / contao-be-field-dependency
允许通过条件来控制DCA字段的输出。
0.4.2
2022-04-27 09:13 UTC
Requires
- php: ^7.4 || ^8.0
- contao/core-bundle: ^4.9
Requires (Dev)
- contao/manager-plugin: ^2.0
Conflicts
- contao/core: *
- contao/manager-plugin: <2.0 || >=3.0
README
除了调色板和子调色板外,此扩展还为DCA添加了新的字段属性(dependsOn
),可以定义条件以显示字段。
基于另一个字段及其值的条件
'field1' => [ 'exclude' => true, 'inputType' => 'checkbox', 'eval' => ['tl_class' => 'w50 m12'], 'sql' => "char(1) NOT NULL default '0'", ], 'field2' => [ 'exclude' => true, 'inputType' => 'text', 'eval' => ['maxlength'=>64, 'tl_class'=>'w50'], 'sql' => "varchar(64) NOT NULL default ''", 'dependsOn' => [ 'field1' => 1 // Displays this field only if the checkbox (field1) has been selected. ] ],
基于另一个字段和自定义回调的条件
'field2' => [ 'exclude' => true, 'inputType' => 'text', 'eval' => ['maxlength'=>64, 'tl_class'=>'w50'], 'sql' => "varchar(64) NOT NULL default ''", 'dependsOn' => [ 'field1' => static function($fieldName, $objModel) { // $fieldName = field1 // "field1" is automatically supplemented with the field evaluation "submitOnChange = true" (autoSubmit = true). // Return true = show / false = hide return $objModel->{$fieldName} == 1; } ] ],
在此变体中,指定要响应的字段名称是可选的。请注意,第一个参数对应于给定的键。
例如
'field2' => [ 'exclude' => true, 'inputType' => 'text', 'eval' => ['maxlength'=>64, 'tl_class'=>'w50'], 'sql' => "varchar(64) NOT NULL default ''", 'dependsOn' => [ static function($fieldName, $objModel, &$arrEvaluationFields) { // $fieldName = 0 // 'field1' must be extended independently with the field evaluation 'submitOnChange = true' or added via the third parameter ($arrFields) (autoSubmit = true). $arrEvaluationFields[] = 'field1'; // Return true = show / false = hide return $objModel->field1 == 1; } ] ],
多个条件
'field1' => [ 'exclude' => true, 'inputType' => 'checkbox', 'eval' => ['tl_class' => 'w50 m12'], 'sql' => "char(1) NOT NULL default '0'", ], 'field2' => [ 'exclude' => true, 'inputType' => 'checkbox', 'eval' => ['tl_class' => 'w50 m12'], 'sql' => "char(1) NOT NULL default '0'", ], 'field3' => [ 'exclude' => true, 'inputType' => 'text', 'eval' => ['maxlength'=>64, 'tl_class'=>'w50'], 'sql' => "varchar(64) NOT NULL default ''", 'dependsOn' => [ 'field2' => 1, 'field3' => 1 // Both fields must be checked to display this field ] ],
配置
基本设置必须通过config/config.yml文件维护。
contao_be_field_dependency: autoSubmit: true tables: - tl_article - tl_content - tl_files - tl_form_field - tl_form - tl_image_size_item - tl_image_size - tl_layout - tl_member_group - tl_member - tl_module - tl_opt_in - tl_page - tl_style - tl_style_sheet - tl_theme - tl_user_group - tl_user