Commit 1c8ace46 by Carsten Brandt

Merge PR #2136 branch 'detail-view-attributes' of https://github.com/creocoder/yii2

* 'detail-view-attributes' of https://github.com/creocoder/yii2: DetailView phpDoc CHANGELOG DetailView allow set label while attribute in string format DetailView correct regexp Conflicts: framework/CHANGELOG.md
parents 0ce2dd18 4dcf22b9
...@@ -87,6 +87,8 @@ Yii Framework 2 Change Log ...@@ -87,6 +87,8 @@ Yii Framework 2 Change Log
- View now falls back to `en` from `en-US` if file not found (samdark) - View now falls back to `en` from `en-US` if file not found (samdark)
- Default `sourceLanguage` and `language` are now `en` (samdark) - Default `sourceLanguage` and `language` are now `en` (samdark)
- Enh #2101: Gii is now using model labels when generating search (thiagotalma) - Enh #2101: Gii is now using model labels when generating search (thiagotalma)
- Enh #2102: DetailView now allow use `category.name` as attribute name (creocoder)
- Enh #2102: DetailView now allow use custom label in string format like `name:format:label` (creocoder)
- Enh #2103: Renamed AccessDeniedHttpException to ForbiddenHttpException, added new commonly used HTTP exception classes (danschmidt5189) - Enh #2103: Renamed AccessDeniedHttpException to ForbiddenHttpException, added new commonly used HTTP exception classes (danschmidt5189)
- Enh #2124: Added support for UNION ALL queries (Ivan Pomortsev, iworker) - Enh #2124: Added support for UNION ALL queries (Ivan Pomortsev, iworker)
- Enh #2132: Allow url of CSS and JS files registered in yii\web\View to be url alias (cebe) - Enh #2132: Allow url of CSS and JS files registered in yii\web\View to be url alias (cebe)
......
...@@ -57,9 +57,11 @@ class DetailView extends Widget ...@@ -57,9 +57,11 @@ 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:Format", where "Name" refers to * An attribute can be specified as a string in the format of "name", "name:format" or "name:format:label",
* the attribute name, and "Format" represents the format of the attribute. The "Format" is passed to the [[Formatter::format()]] * where "name" refers to the attribute name, and "format" represents the format of the attribute. The "format"
* method to format an attribute value into a displayable text. Please refer to [[Formatter]] for the supported types. * is passed to the [[Formatter::format()]] method to format an attribute value into a displayable text.
* Please refer to [[Formatter]] for the supported types. Both "format" and "label" are optional.
* They will take default values if absent.
* *
* 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:
* *
...@@ -173,12 +175,13 @@ class DetailView extends Widget ...@@ -173,12 +175,13 @@ 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\.]+)(:(\w*))?(:(.*))?$/', $attribute, $matches)) {
throw new InvalidConfigException('The attribute must be specified in the format of "Name" or "Name:Format"'); throw new InvalidConfigException('The attribute must be specified in the format of "name", "name:format" or "name:format:label"');
} }
$attribute = [ $attribute = [
'name' => $matches[1], 'name' => $matches[1],
'format' => isset($matches[3]) ? $matches[3] : 'text', 'format' => isset($matches[3]) ? $matches[3] : 'text',
'label' => isset($matches[5]) ? $matches[5] : null,
]; ];
} }
......
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