Commit c7ef701d by Carsten Brandt

Renamed DetailView attribute type to format

for consistency with GridViews DataColumn where the same property is also named format
parent f3ab5d99
...@@ -57,8 +57,8 @@ class DetailView extends Widget ...@@ -57,8 +57,8 @@ class DetailView extends Widget
* @var array a list of attributes to be displayed in the detail view. Each array element * @var array a list of attributes to be displayed in the detail view. Each array element
* represents the specification for displaying one particular attribute. * represents the specification for displaying one particular attribute.
* *
* An attribute can be specified as a string in the format of "Name" or "Name:Type", where "Name" refers to * An attribute can be specified as a string in the format of "Name" or "Name:Format", where "Name" refers to
* the attribute name, and "Type" represents the type of the attribute. The "Type" is passed to the [[Formatter::format()]] * the attribute name, and "Format" represents the format of the attribute. The "Format" is passed to the [[Formatter::format()]]
* method to format an attribute value into a displayable text. Please refer to [[Formatter]] for the supported types. * method to format an attribute value into a displayable text. Please refer to [[Formatter]] for the supported types.
* *
* An attribute can also be specified in terms of an array with the following elements: * An attribute can also be specified in terms of an array with the following elements:
...@@ -67,8 +67,8 @@ class DetailView extends Widget ...@@ -67,8 +67,8 @@ class DetailView extends Widget
* - label: the label associated with the attribute. If this is not specified, it will be generated from the attribute name. * - label: the label associated with the attribute. If this is not specified, it will be generated from the attribute name.
* - value: the value to be displayed. If this is not specified, it will be retrieved from [[model]] using the attribute name * - value: the value to be displayed. If this is not specified, it will be retrieved from [[model]] using the attribute name
* by calling [[ArrayHelper::getValue()]]. Note that this value will be formatted into a displayable text * by calling [[ArrayHelper::getValue()]]. Note that this value will be formatted into a displayable text
* according to the "type" option. * according to the "format" option.
* - type: the type of the value that determines how the value would be formatted into a displayable text. * - format: the type of the value that determines how the value would be formatted into a displayable text.
* Please refer to [[Formatter]] for supported types. * Please refer to [[Formatter]] for supported types.
* - visible: whether the attribute is visible. If set to `false`, the attribute will be displayed. * - visible: whether the attribute is visible. If set to `false`, the attribute will be displayed.
*/ */
...@@ -145,7 +145,7 @@ class DetailView extends Widget ...@@ -145,7 +145,7 @@ class DetailView extends Widget
if (is_string($this->template)) { if (is_string($this->template)) {
return strtr($this->template, [ return strtr($this->template, [
'{label}' => $attribute['label'], '{label}' => $attribute['label'],
'{value}' => $this->formatter->format($attribute['value'], $attribute['type']), '{value}' => $this->formatter->format($attribute['value'], $attribute['format']),
]); ]);
} else { } else {
return call_user_func($this->template, $attribute, $index, $this); return call_user_func($this->template, $attribute, $index, $this);
...@@ -174,11 +174,11 @@ class DetailView extends Widget ...@@ -174,11 +174,11 @@ class DetailView extends Widget
foreach ($this->attributes as $i => $attribute) { foreach ($this->attributes as $i => $attribute) {
if (is_string($attribute)) { if (is_string($attribute)) {
if (!preg_match('/^(\w+)(\s*:\s*(\w+))?$/', $attribute, $matches)) { if (!preg_match('/^(\w+)(\s*:\s*(\w+))?$/', $attribute, $matches)) {
throw new InvalidConfigException('The attribute must be specified in the format of "Name" or "Name:Type"'); throw new InvalidConfigException('The attribute must be specified in the format of "Name" or "Name:Format"');
} }
$attribute = [ $attribute = [
'name' => $matches[1], 'name' => $matches[1],
'type' => isset($matches[3]) ? $matches[3] : 'text', 'format' => isset($matches[3]) ? $matches[3] : 'text',
]; ];
} }
...@@ -186,8 +186,8 @@ class DetailView extends Widget ...@@ -186,8 +186,8 @@ class DetailView extends Widget
throw new InvalidConfigException('The attribute configuration must be an array.'); throw new InvalidConfigException('The attribute configuration must be an array.');
} }
if (!isset($attribute['type'])) { if (!isset($attribute['format'])) {
$attribute['type'] = 'text'; $attribute['format'] = 'text';
} }
if (isset($attribute['name'])) { if (isset($attribute['name'])) {
$name = $attribute['name']; $name = $attribute['name'];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment