Completed
Push — master ( 546114...e895bf )
by Pavel
03:26
created

ToolbarButton::renderButton()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 20
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 20
rs 9.4285
cc 3
eloc 10
nc 4
nop 0
1
<?php
2
3
/**
4
 * @copyright   Copyright (c) 2015 ublaboo <[email protected]>
5
 * @author      Pavel Janda <[email protected]>
6
 * @package     Ublaboo
7
 */
8
9
namespace Ublaboo\DataGrid\Toolbar;
10
11
use Nette\Utils\Html;
12
use Ublaboo\DataGrid\DataGrid;
13
use Ublaboo\DataGrid\Traits;
14
15
class ToolbarButton
16
{
17
18
	use Traits\TButton;
19
	use Traits\TLink;
20
21
	/**
22
	 * @var DataGrid
23
	 */
24
	protected $grid;
25
26
	/**
27
	 * @var string
28
	 */
29
	protected $href;
30
31
	/**
32
	 * @var array
33
	 */
34
	protected $params;
35
36
	/**
37
	 * @param DataGrid $grid
38
	 * @param string   $href
39
	 * @param string   $text
40
	 * @param array    $params
41
	 */
42
	public function __construct(DataGrid $grid, $href, $text, $params = [])
43
	{
44
		$this->grid = $grid;
45
		$this->href = $href;
46
		$this->text = $text;
47
		$this->params = $params;
48
	}
49
50
51
	/**
52
	 * Render toolbar button
53
	 * @return Html
54
	 */
55
	public function renderButton()
56
	{
57
		$link = $this->createLink($this->grid, $this->href, $this->params);
58
59
		$a = Html::el('a')->href($link);
60
61
		$this->tryAddIcon($a, $this->getIcon(), $this->getText());
62
63
		$a->add($this->text);
64
65
		if ($this->title) {
66
			$a->title($this->grid->getTranslator()->translate($this->title));
67
		}
68
69
		if ($this->class) {
70
			$a->class($this->class);
71
		}
72
73
		return $a;
74
	}
75
76
}
77