diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index a6aec0a4e2..eb42d3e98f 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -178,6 +178,7 @@ Yii Framework 2 Change Log - Enh: LinkPager can now register relational link tags in the html header for prev, next, first and last page (cebe) - Enh: Added `yii\web\UrlRuleInterface` and `yii\web\CompositeUrlRule` (qiangxue) - Enh: Added `yii\web\Request::getAuthUser()` and `getAuthPassword()` (qiangxue) +- Enh: Added summaryOptions and emptyTextOptions to BaseListView (johonunu) - Chg #47: Changed Markdown library to cebe/markdown and adjusted Markdown helper API (cebe) - Chg #735: Added back `ActiveField::hiddenInput()` (qiangxue) - Chg #1186: Changed `Sort` to use comma to separate multiple sort fields and use negative sign to indicate descending sort (qiangxue) diff --git a/framework/widgets/BaseListView.php b/framework/widgets/BaseListView.php index e31f00377d..e26519a114 100644 --- a/framework/widgets/BaseListView.php +++ b/framework/widgets/BaseListView.php @@ -53,6 +53,12 @@ abstract class BaseListView extends Widget * - `{pageCount}`: the number of pages available */ public $summary; + /** + * @var array the HTML attributes for the summary of the list view. + * The "tag" element specifies the tag name of the summary element and defaults to "div". + * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. + */ + public $summaryOptions = ['class' => 'summary']; /** * @var boolean whether to show the list view if [[dataProvider]] returns no data. */ @@ -61,6 +67,12 @@ abstract class BaseListView extends Widget * @var string the HTML content to be displayed when [[dataProvider]] does not have any data. */ public $emptyText; + /** + * @var array the HTML attributes for the emptyText of the list view. + * The "tag" element specifies the tag name of the emptyText element and defaults to "div". + * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. + */ + public $emptyTextOptions = ['class' => 'empty']; /** * @var string the layout that determines how different sections of the list view should be organized. * The following tokens will be replaced with the corresponding section contents: @@ -139,7 +151,8 @@ abstract class BaseListView extends Widget */ public function renderEmpty() { - return '
' . ($this->emptyText === null ? Yii::t('yii', 'No results found.') : $this->emptyText) . '
'; + $tag = ArrayHelper::remove($this->emptyTextOptions, 'tag', 'div'); + return Html::tag($tag, ($this->emptyText === null ? Yii::t('yii', 'No results found.') : $this->emptyText), $this->emptyTextOptions); } /** @@ -151,6 +164,7 @@ abstract class BaseListView extends Widget if ($count <= 0) { return ''; } + $tag = ArrayHelper::remove($this->summaryOptions, 'tag', 'div'); if (($pagination = $this->dataProvider->getPagination()) !== false) { $totalCount = $this->dataProvider->getTotalCount(); $begin = $pagination->getPage() * $pagination->pageSize + 1; @@ -161,29 +175,27 @@ abstract class BaseListView extends Widget $page = $pagination->getPage() + 1; $pageCount = $pagination->pageCount; if (($summaryContent = $this->summary) === null) { - return '
' - . Yii::t('yii', 'Showing {begin, number}-{end, number} of {totalCount, number} {totalCount, plural, one{item} other{items}}.', [ + return Html::tag($tag, Yii::t('yii', 'Showing {begin, number}-{end, number} of {totalCount, number} {totalCount, plural, one{item} other{items}}.', [ 'begin' => $begin, 'end' => $end, 'count' => $count, 'totalCount' => $totalCount, 'page' => $page, 'pageCount' => $pageCount, - ]) - . '
'; + ]), $this->summaryOptions); } } else { $begin = $page = $pageCount = 1; $end = $totalCount = $count; if (($summaryContent = $this->summary) === null) { - return '
' . Yii::t('yii', 'Total {count, number} {count, plural, one{item} other{items}}.', [ + return Html::tag($tag, Yii::t('yii', 'Total {count, number} {count, plural, one{item} other{items}}.', [ 'begin' => $begin, 'end' => $end, 'count' => $count, 'totalCount' => $totalCount, 'page' => $page, 'pageCount' => $pageCount, - ]) . '
'; + ]), $this->summaryOptions); } }