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

contributte / forms-multiplier / 5574364510

pending completion
5574364510

push

github

f3l1x
Composer: update dev deps

239 of 321 relevant lines covered (74.45%)

10.95 hits per line

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

70.0
/src/Buttons/CreateButton.php
1
<?php declare(strict_types = 1);
2

3
namespace Contributte\FormMultiplier\Buttons;
4

5
use Contributte\FormMultiplier\Multiplier;
6
use Contributte\FormMultiplier\Submitter;
7
use Nette\SmartObject;
8

9
final class CreateButton
10
{
11

12
        use SmartObject;
13

14
        /** @var callable[] */
15
        public array $onCreate = [];
16

17
        private ?string $caption = null;
18

19
        private int $copyCount;
20

21
        /** @var mixed[]|null */
22
        private ?array $validationScope = null;
23

24
        /** @var string[] */
25
        private array $classes = [];
26

27
        public function __construct(?string $caption, int $copyCount = 1)
28
        {
29
                $this->caption = $caption;
21✔
30
                $this->copyCount = $copyCount;
21✔
31
        }
32

33
        public function addOnCreateCallback(callable $onCreate): self
34
        {
35
                $this->onCreate[] = $onCreate;
2✔
36

37
                return $this;
2✔
38
        }
39

40
        public function setNoValidate(): self
41
        {
42
                $this->setValidationScope([]);
×
43

44
                return $this;
×
45
        }
46

47
        public function addClass(string $class): self
48
        {
49
                $this->classes[] = $class;
×
50

51
                return $this;
×
52
        }
53

54
        /**
55
         * @param mixed[]|null $validationScope
56
         */
57
        public function setValidationScope(?array $validationScope): self
58
        {
59
                $this->validationScope = $validationScope;
×
60

61
                return $this;
×
62
        }
63

64
        public function getComponentName(): string
65
        {
66
                return Multiplier::SUBMIT_CREATE_NAME . ($this->copyCount === 1 ? '' : $this->copyCount);
21✔
67
        }
68

69
        public function getCopyCount(): int
70
        {
71
                return $this->copyCount;
1✔
72
        }
73

74
        public function create(Multiplier $multiplier): Submitter
75
        {
76
                $button = new Submitter($this->caption, $this->copyCount);
21✔
77

78
                $button->setHtmlAttribute('class', implode(' ', $this->classes));
21✔
79
                $button->setValidationScope($this->validationScope ?? [$multiplier])
21✔
80
                        ->setOmitted();
21✔
81

82
                foreach ($this->onCreate as $callback) {
21✔
83
                        $callback($button);
2✔
84
                }
85

86
                $button->onClick[] = [$multiplier, 'resetFormEvents'];
21✔
87

88
                return $button;
21✔
89
        }
90

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