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

contributte / datagrid / 8230157862

11 Mar 2024 09:02AM UTC coverage: 34.102%. First build
8230157862

Pull #1060

github

radimvaculik
Fix failing tests
Pull Request #1060: [7.x] Next

117 of 435 new or added lines in 54 files covered. (26.9%)

1124 of 3296 relevant lines covered (34.1%)

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
        protected array $attributes = [];
28

29
        protected ?string $confirmDialog = null;
30

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

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

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

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

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

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

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

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

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

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

76
                return $a;
×
77
        }
78

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

86
                return $this;
×
87
        }
88

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

96
                return $this;
×
97
        }
98

99
}
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