Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e687dff

Browse filesBrowse files
committed
Allow to set block_id for SlackActionsBlock and set url to nullable, allow setting value in SlackButtonBlockElement
1 parent 5276de0 commit e687dff
Copy full SHA for e687dff

File tree

3 files changed

+30
-5
lines changed
Filter options

3 files changed

+30
-5
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Notifier/Bridge/Slack/Block/SlackActionsBlock.php
+10-2
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,24 @@ public function __construct()
2424
/**
2525
* @return $this
2626
*/
27-
public function button(string $text, string $url, ?string $style = null): static
27+
public function button(string $text, ?string $url = null, ?string $style = null, ?string $value = 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);
33+
$element = new SlackButtonBlockElement($text, $url, $style, $value);
3434

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

3737
return $this;
3838
}
39+
40+
/**
41+
* @return $this
42+
*/
43+
public function id(string $id): static
44+
{
45+
$this->options['block_id'] = $id;
46+
}
3947
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Notifier/Bridge/Slack/Block/SlackButtonBlockElement.php
+9-2
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,27 @@
1616
*/
1717
final class SlackButtonBlockElement extends AbstractSlackBlockElement
1818
{
19-
public function __construct(string $text, string $url, ?string $style = null)
19+
public function __construct(string $text, ?string $url = null, ?string $style = null, ?string $value = null)
2020
{
2121
$this->options = [
2222
'type' => 'button',
2323
'text' => [
2424
'type' => 'plain_text',
2525
'text' => $text,
2626
],
27-
'url' => $url,
2827
];
2928

29+
if ($url) {
30+
$this->options['url'] = $url;
31+
}
32+
3033
if ($style) {
3134
// primary or danger
3235
$this->options['style'] = $style;
3336
}
37+
38+
if ($value) {
39+
$this->options['value'] = $value;
40+
}
3441
}
3542
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Notifier/Bridge/Slack/Tests/Block/SlackActionsBlockTest.php
+11-1
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ final class SlackActionsBlockTest extends TestCase
1919
public function testCanBeInstantiated()
2020
{
2121
$actions = new SlackActionsBlock();
22-
$actions->button('first button text', 'https://example.org')
22+
$actions->button('first button text', 'https://example.org', null, 'test-value')
2323
->button('second button text', 'https://example.org/slack', 'danger')
24+
->button('third button text', null, null, 'test-value-3')
2425
;
2526

2627
$this->assertSame([
@@ -33,6 +34,7 @@ public function testCanBeInstantiated()
3334
'text' => 'first button text',
3435
],
3536
'url' => 'https://example.org',
37+
'value' => 'test-value'
3638
],
3739
[
3840
'type' => 'button',
@@ -43,6 +45,14 @@ public function testCanBeInstantiated()
4345
'url' => 'https://example.org/slack',
4446
'style' => 'danger',
4547
],
48+
[
49+
'type' => 'button',
50+
'text' => [
51+
'type' => 'plain_text',
52+
'text' => 'third button text',
53+
],
54+
'value' => 'test-value-3',
55+
]
4656
],
4757
], $actions->toArray());
4858
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.