Skip to content

Commit c9602f0

Browse files
Taras Hinykfabpot
authored andcommitted
[Notifier] Add support for confirm option in Slack buttons API
1 parent 49d7f9f commit c9602f0

File tree

5 files changed

+72
-4
lines changed

5 files changed

+72
-4
lines changed

src/Symfony/Component/Notifier/Bridge/Slack/Block/SlackActionsBlock.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ public function __construct()
2424
/**
2525
* @return $this
2626
*/
27-
public function button(string $text, ?string $url = null, ?string $style = null, ?string $value = null): static
27+
public function button(string $text, ?string $url = null, ?string $style = null, ?string $value = null, ?array $confirm = null): static
2828
{
2929
if (25 === \count($this->options['elements'] ?? [])) {
3030
throw new \LogicException('Maximum number of buttons should not exceed 25.');
3131
}
3232

33-
$element = new SlackButtonBlockElement($text, $url, $style, $value);
33+
$element = new SlackButtonBlockElement($text, $url, $style, $value, $confirm);
3434

3535
$this->options['elements'][] = $element->toArray();
3636

src/Symfony/Component/Notifier/Bridge/Slack/Block/SlackButtonBlockElement.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
final class SlackButtonBlockElement extends AbstractSlackBlockElement
1818
{
19-
public function __construct(string $text, ?string $url = null, ?string $style = null, ?string $value = null)
19+
public function __construct(string $text, ?string $url = null, ?string $style = null, ?string $value = null, ?array $confirm = null)
2020
{
2121
$this->options = [
2222
'type' => 'button',
@@ -38,5 +38,9 @@ public function __construct(string $text, ?string $url = null, ?string $style =
3838
if ($value) {
3939
$this->options['value'] = $value;
4040
}
41+
42+
if ($confirm) {
43+
$this->options['confirm'] = $confirm;
44+
}
4145
}
4246
}

src/Symfony/Component/Notifier/Bridge/Slack/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
7.4
5+
---
6+
7+
* Add `confirm` option to `button` method in `SlackActionsBlock` block
8+
49
7.2
510
---
611

src/Symfony/Component/Notifier/Bridge/Slack/README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,14 @@ $contributeToSymfonyBlocks = (new SlackActionsBlock())
5252
->button(
5353
'Report bugs',
5454
'https://symfony.com/doc/current/contributing/code/bugs.html',
55-
'danger'
55+
'danger',
56+
null,
57+
[
58+
'title' => ['type' => 'plaint_text', 'text' => 'Report a bug'],
59+
'text' => ['type' => 'plaint_text', 'text' => 'By proceeding I confirm I\'ve read the guidelines.'],
60+
'confirm' => ['type' => 'plaint_text', 'text' => 'Proceed'],
61+
'deny' => ['type' => 'plaint_text', 'text' => 'Go back to reading']
62+
]
5663
);
5764

5865
$slackOptions = (new SlackOptions())

src/Symfony/Component/Notifier/Bridge/Slack/Tests/Block/SlackActionsBlockTest.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,31 @@ public function testCanBeInstantiated()
2222
$actions->button('first button text', 'https://example.org', null, 'test-value')
2323
->button('second button text', 'https://example.org/slack', 'danger')
2424
->button('third button text', null, null, 'test-value-3')
25+
->button(
26+
'fourth button text',
27+
null,
28+
null,
29+
'test-value-4',
30+
[
31+
'title' => [
32+
'type' => 'plain_text',
33+
'text' => 'test-confirm-title-4',
34+
],
35+
'text' => [
36+
'type' => 'plain_text',
37+
'text' => 'test-confirm-text-4',
38+
],
39+
'confirm' => [
40+
'type' => 'plain_text',
41+
'text' => 'test-confirm-confirm-4',
42+
],
43+
'deny' => [
44+
'type' => 'plain_text',
45+
'text' => 'test-confirm-deny-4',
46+
],
47+
'style' => 'danger',
48+
]
49+
)
2550
;
2651

2752
$this->assertSame([
@@ -53,6 +78,33 @@ public function testCanBeInstantiated()
5378
],
5479
'value' => 'test-value-3',
5580
],
81+
[
82+
'type' => 'button',
83+
'text' => [
84+
'type' => 'plain_text',
85+
'text' => 'fourth button text',
86+
],
87+
'value' => 'test-value-4',
88+
'confirm' => [
89+
'title' => [
90+
'type' => 'plain_text',
91+
'text' => 'test-confirm-title-4',
92+
],
93+
'text' => [
94+
'type' => 'plain_text',
95+
'text' => 'test-confirm-text-4',
96+
],
97+
'confirm' => [
98+
'type' => 'plain_text',
99+
'text' => 'test-confirm-confirm-4',
100+
],
101+
'deny' => [
102+
'type' => 'plain_text',
103+
'text' => 'test-confirm-deny-4',
104+
],
105+
'style' => 'danger',
106+
],
107+
],
56108
],
57109
], $actions->toArray());
58110
}

0 commit comments

Comments
 (0)