Commit 3dd3914a by Qiang Xue

Fixes #2144: `Html` helper now supports rendering "data" attributes

parent a19dd39e
......@@ -71,6 +71,7 @@ Yii Framework 2 Change Log
- Enh #1706: Added support for registering a single JS/CSS file with dependency (qiangxue)
- Enh #1773: keyPrefix property of Cache is not restricted to alnum characters anymore, however it is still recommended (cebe)
- Enh #1809: Added support for building "EXISTS" and "NOT EXISTS" query conditions (abdrasulov)
- Enh #1839: Added support for getting file extension and basename from uploaded file (anfrantic)
- Enh #1852: ActiveRecord::tableName() now returns table name using DbConnection::tablePrefix (creocoder)
- Enh #1894: The path aliases `@webroot` and `@web` are now available right after the application is initialized (qiangxue)
- Enh #1921: Grid view ActionColumn now allow to name buttons like `{controller/action}` (creocoder)
......@@ -88,6 +89,7 @@ Yii Framework 2 Change Log
- 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 #2132: Allow url of CSS and JS files registered in yii\web\View to be url alias (cebe)
- Enh #2144: `Html` helper now supports rendering "data" attributes (qiangxue)
- Enh: Added `favicon.ico` and `robots.txt` to default application templates (samdark)
- Enh: Added `Widget::autoIdPrefix` to support prefixing automatically generated widget IDs (qiangxue)
- Enh: Support for file aliases in console command 'message' (omnilight)
......@@ -97,7 +99,6 @@ Yii Framework 2 Change Log
- Enh: Better exception message when class cannot be loaded (samdark)
- Enh: `init` of advanced application now allows to specify answer for overwriting files via `init --overwrite=n` (samdark)
- Enh: Added `TableSchema::fullName` property (qiangxue)
- Enh #1839: Added support for getting file extension and basename from uploaded file (anfrantic)
- Enh: yii\codeception\TestCase now supports loading and using fixtures via Yii fixture framework (qiangxue)
- Enh: Added support to parse json request data to Request::getRestParams() (cebe)
- Enh: Added ability to get incoming headers (dizews)
......
......@@ -1419,9 +1419,17 @@ class BaseHtml
/**
* Renders the HTML tag attributes.
*
* Attributes whose values are of boolean type will be treated as
* [boolean attributes](http://www.w3.org/TR/html5/infrastructure.html#boolean-attributes).
* And attributes whose values are null will not be rendered.
*
* Attributes whose values are null will not be rendered.
*
* The "data" attribute is specially handled when it is receiving an array value. In this case,
* the array will be "expanded" and a list data attributes will be rendered. For example,
* if `'data' => ['id' => 1, 'name' => 'yii']`, then this will be rendered:
* `data-id="1" data-name="yii"`.
*
* @param array $attributes attributes to be rendered. The attribute values will be HTML-encoded using [[encode()]].
* @return string the rendering result. If the attributes are not empty, they will be rendered
* into a string with a leading white space (so that it can be directly appended to the tag name
......@@ -1445,6 +1453,10 @@ class BaseHtml
if ($value) {
$html .= " $name";
}
} elseif (is_array($value) && $name === 'data') {
foreach ($value as $n => $v) {
$html .= "$name-$n\"" . static::encode($v) . '"';
}
} elseif ($value !== null) {
$html .= " $name=\"" . static::encode($value) . '"';
}
......
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