From e19737e132f9d0822668d8a65aff0871a4854e16 Mon Sep 17 00:00:00 2001 From: artur Date: Thu, 22 May 2014 01:55:08 +0300 Subject: [PATCH 1/4] Hide output when only one page exist --- framework/widgets/LinkPager.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/framework/widgets/LinkPager.php b/framework/widgets/LinkPager.php index 1b3172e2cf..e610f0a140 100644 --- a/framework/widgets/LinkPager.php +++ b/framework/widgets/LinkPager.php @@ -140,9 +140,12 @@ class LinkPager extends Widget */ protected function renderPageButtons() { - $buttons = []; - $pageCount = $this->pagination->getPageCount(); + if ($pageCount < 2) { + return ''; + } + + $buttons = []; $currentPage = $this->pagination->getPage(); // first page From e860f218cfbae306109bc9fb21565ec60522ee00 Mon Sep 17 00:00:00 2001 From: artur Date: Thu, 22 May 2014 03:01:58 +0300 Subject: [PATCH 2/4] Add param for configuring rendering result with one page --- framework/widgets/LinkPager.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/framework/widgets/LinkPager.php b/framework/widgets/LinkPager.php index e610f0a140..6da42f6470 100644 --- a/framework/widgets/LinkPager.php +++ b/framework/widgets/LinkPager.php @@ -98,6 +98,10 @@ class LinkPager extends Widget * @see registerLinkTags() */ public $registerLinkTags = false; + /** + * @var boolean Render widget when only one page exist. Defaults to `false`. + */ + public $showWrapper = false; /** * Initializes the pager. @@ -141,10 +145,10 @@ class LinkPager extends Widget protected function renderPageButtons() { $pageCount = $this->pagination->getPageCount(); - if ($pageCount < 2) { + if ($pageCount < 2 && !$this->showWrapper) { return ''; } - + $buttons = []; $currentPage = $this->pagination->getPage(); From 6c25675d7ef537a131d3c649e2958f4714678ede Mon Sep 17 00:00:00 2001 From: artur Date: Thu, 22 May 2014 10:18:06 +0300 Subject: [PATCH 3/4] Changed param name --- framework/widgets/LinkPager.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/widgets/LinkPager.php b/framework/widgets/LinkPager.php index 6da42f6470..aa809236b2 100644 --- a/framework/widgets/LinkPager.php +++ b/framework/widgets/LinkPager.php @@ -101,7 +101,7 @@ class LinkPager extends Widget /** * @var boolean Render widget when only one page exist. Defaults to `false`. */ - public $showWrapper = false; + public $renderOnSinglePage = false; /** * Initializes the pager. @@ -145,7 +145,7 @@ class LinkPager extends Widget protected function renderPageButtons() { $pageCount = $this->pagination->getPageCount(); - if ($pageCount < 2 && !$this->showWrapper) { + if ($pageCount < 2 && !$this->renderOnSinglePage) { return ''; } From 5a1702e77c425db6ff296f394073bbd7fe463002 Mon Sep 17 00:00:00 2001 From: artur Date: Thu, 22 May 2014 13:40:55 +0300 Subject: [PATCH 4/4] Refactor --- framework/CHANGELOG.md | 1 + framework/widgets/LinkPager.php | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index b46901ae1b..9f0519a1d8 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -59,6 +59,7 @@ Yii Framework 2 Change Log - Enh: Added `all` option to `MigrateController::actionDown()` action (creocoder, umneeq) - Enh: Added support for array attributes in `exist` validator (creocoder) - Enh: Added support for using path alias with `FileDependency::fileName` (qiangxue) +- Enh: Added param `hideOnSinglePage` to `yii\widgets\LinkPager` (arturf) - Chg #2913: RBAC `DbManager` is now initialized via migration (samdark) - Chg #3036: Upgraded Twitter Bootstrap to 3.1.x (qiangxue) - Chg #3175: InvalidCallException, InvalidParamException, UnknownMethodException are now extended from SPL BadMethodCallException (samdark) diff --git a/framework/widgets/LinkPager.php b/framework/widgets/LinkPager.php index aa809236b2..76a4b099a2 100644 --- a/framework/widgets/LinkPager.php +++ b/framework/widgets/LinkPager.php @@ -99,9 +99,9 @@ class LinkPager extends Widget */ public $registerLinkTags = false; /** - * @var boolean Render widget when only one page exist. Defaults to `false`. + * @var boolean Hide widget when only one page exist. Defaults to `false`. */ - public $renderOnSinglePage = false; + public $hideOnSinglePage = false; /** * Initializes the pager. @@ -145,7 +145,7 @@ class LinkPager extends Widget protected function renderPageButtons() { $pageCount = $this->pagination->getPageCount(); - if ($pageCount < 2 && !$this->renderOnSinglePage) { + if ($pageCount < 2 && $this->hideOnSinglePage) { return ''; }