-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBootstrapLinkPager.php
68 lines (55 loc) · 1.8 KB
/
BootstrapLinkPager.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
namespace app\components;
use Yii;
use yii\helpers\Html;
use yii\widgets\LinkPager;
class BootstrapLinkPager extends LinkPager
{
/**
* @inheritdoc
*/
public function init()
{
parent::init();
// In Bootstrap 4 no div's "next" and "prev", so you need to overwrite the default values
$this->prevPageCssClass = 'page-item';
$this->nextPageCssClass = 'page-item';
// Change the location and size of block
// https://v4-alpha.getbootstrap.com/components/pagination/#alignment
// https://v4-alpha.getbootstrap.com/components/pagination/#sizing
$this->options['class'] = 'pagination justify-content-center';
// Change standard arrows "«" and "»"
$this->nextPageLabel = Yii::t('app', 'Next');
$this->prevPageLabel = Yii::t('app', 'Previous');
// Default div for links
$this->linkOptions['class'] = 'page-link';
}
/**
* @inheritdoc
*/
public function run()
{
if ($this->registerLinkTags) {
$this->registerLinkTags();
}
if ($this->pagination->getPageCount() > 1) {
echo Html::tag('nav', $this->renderPageButtons());
}
}
/**
* @inheritdoc
*/
protected function renderPageButton($label, $page, $class, $disabled, $active)
{
$options = ['class' => empty($class) ? 'page-item' : $class];
$linkOptions = $this->linkOptions;
if ($active) {
Html::addCssClass($options, $this->activePageCssClass);
}
if ($disabled) {
Html::addCssClass($options, $this->disabledPageCssClass);
$linkOptions['tabindex'] = '-1';
}
return Html::tag('li', Html::a($label, $this->pagination->createUrl($page), $linkOptions), $options);
}
}