• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

contributte / datagrid / 7048127238

30 Nov 2023 02:47PM UTC coverage: 34.081%. First build
7048127238

Pull #1060

github

paveljanda
Minor CSS changes for the next verison of datagrid
Pull Request #1060: [7.x] Next

118 of 431 new or added lines in 54 files covered. (27.38%)

1125 of 3301 relevant lines covered (34.08%)

0.34 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Toolbar/ToolbarButton.php
1
<?php declare(strict_types = 1);
2

3
namespace Contributte\Datagrid\Toolbar;
4

5
use Contributte\Datagrid\Datagrid;
6
use Contributte\Datagrid\Exception\DatagridColumnRendererException;
7
use Contributte\Datagrid\Traits\TButtonClass;
8
use Contributte\Datagrid\Traits\TButtonIcon;
9
use Contributte\Datagrid\Traits\TButtonRenderer;
10
use Contributte\Datagrid\Traits\TButtonText;
11
use Contributte\Datagrid\Traits\TButtonTitle;
12
use Contributte\Datagrid\Traits\TButtonTryAddIcon;
13
use Contributte\Datagrid\Traits\TLink;
14
use Nette\Utils\Html;
15

16
class ToolbarButton
17
{
18

19
        use TButtonTryAddIcon;
20
        use TButtonClass;
21
        use TButtonIcon;
22
        use TButtonRenderer;
23
        use TButtonText;
24
        use TButtonTitle;
25
        use TLink;
26

27
        /** @var array */
28
        protected array $attributes = [];
29

30
        protected ?string $confirmDialog = null;
31

32
        /**
33
         * Toolbar button constructor
34
         */
NEW
35
        public function __construct(protected Datagrid $grid, protected string $href, string $text, protected array $params = [])
×
36
        {
37
                $this->text = $text;
×
38
        }
39

40
        /**
41
         * Render toolbar button
42
         */
43
        public function renderButton(): Html
44
        {
45
                try {
46
                        // Renderer function may be used
47
                        return $this->useRenderer();
×
NEW
48
                } catch (DatagridColumnRendererException) {
×
49
                        // Do not use renderer
50
                }
51

52
                $link = $this->createLink($this->grid, $this->href, $this->params);
×
53

54
                $a = Html::el('a')->href($link);
×
55

56
                $this->tryAddIcon($a, $this->getIcon(), $this->getText());
×
57

58
                if ($this->attributes !== []) {
×
59
                        $a->addAttributes($this->attributes);
×
60
                }
61

62
                $a->addText($this->grid->getTranslator()->translate($this->text));
×
63

64
                if ($this->getTitle() !== null) {
×
65
                        $a->setAttribute(
×
66
                                'title',
×
67
                                $this->grid->getTranslator()->translate($this->getTitle())
×
68
                        );
69
                }
70

71
                $a->setAttribute('class', $this->getClass());
×
72

73
                if ($this->confirmDialog !== null) {
×
74
                        $a->setAttribute('data-datagrid-confirm', $this->confirmDialog);
×
75
                }
76

77
                return $a;
×
78
        }
79

80
        /**
81
         * @return static
82
         */
83
        public function addAttributes(array $attrs): static
84
        {
85
                $this->attributes += $attrs;
×
86

87
                return $this;
×
88
        }
89

90
        /**
91
         * Add Confirm dialog
92
         */
93
        public function setConfirmDialog(string $confirmDialog): self
94
        {
95
                $this->confirmDialog = $confirmDialog;
×
96

97
                return $this;
×
98
        }
99

100
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc