dictionary 检查器类型允许创建键值对,其用户界面简单,由一个两列表格组成。default 参数(如果指定)应该包含一个键值对象。
public function defineProperties()
{
return [
'options' => [
'title' => 'Options',
'type' => 'dictionary',
'default' => ['option1' => 'Option 1'],
]
];
}生成的输出是一个字符串值,对应于所选选项,例如:
"options": {"option1": "Option 1", "option2": "Option 2"}以下 配置值 是常用的。
| Property | Description |
|---|---|
| title | title for the property. |
| description | a brief description of the property, optional. |
| default | specifies a default an array of keys and values, optional. |
dictionary 编辑器支持针对整个集合 (required 和 length 验证器) 以及针对键和值分别进行验证。参见 验证描述 了解更多详情。validationKey 和 validationValue 定义了针对键和值的验证,例如:
public function defineProperties()
{
return [
'options' => [
'title' => 'Options',
'type' => 'dictionary',
'validation' => [
'required' => [
'message' => 'Please create options'
],
'length' => [
'min' => [
'value' => 2,
'message' => 'Create at least two options.'
]
]
],
'validationKey' => [
'regex' => [
'pattern' => '^[a-z]+
,
'message' => 'Keys can contain only lowercase Latin letters'
]
],
'validationValue' => [
'regex' => [
'pattern' => '^[a-zA-Z0-9]+
,
'message' => 'Values can contain only Latin letters and digits'
]
]
]
];
}