Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ public function __construct()
/**
* @return $this
*/
public function button(string $text, ?string $url = null, ?string $style = null, ?string $value = null): static
public function button(string $text, ?string $url = null, ?string $style = null, ?string $value = null, ?array $confirm = null): static
{
if (25 === \count($this->options['elements'] ?? [])) {
throw new \LogicException('Maximum number of buttons should not exceed 25.');
}

$element = new SlackButtonBlockElement($text, $url, $style, $value);
$element = new SlackButtonBlockElement($text, $url, $style, $value, $confirm);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
final class SlackButtonBlockElement extends AbstractSlackBlockElement
{
public function __construct(string $text, ?string $url = null, ?string $style = null, ?string $value = null)
public function __construct(string $text, ?string $url = null, ?string $style = null, ?string $value = null, ?array $confirm = null)
{
$this->options = [
'type' => 'button',
Expand All @@ -38,5 +38,9 @@ public function __construct(string $text, ?string $url = null, ?string $style =
if ($value) {
$this->options['value'] = $value;
}

if ($confirm) {
$this->options['confirm'] = $confirm;
}
}
}
5 changes: 5 additions & 0 deletions src/Symfony/Component/Notifier/Bridge/Slack/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

7.4
---

* Add `confirm` option to `button` method in `SlackActionsBlock` block

7.2
---

Expand Down
9 changes: 8 additions & 1 deletion src/Symfony/Component/Notifier/Bridge/Slack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,14 @@ $contributeToSymfonyBlocks = (new SlackActionsBlock())
->button(
'Report bugs',
'https://symfony.com/doc/current/contributing/code/bugs.html',
'danger'
'danger',
null,
[
'title' => ['type' => 'plaint_text', 'text' => 'Report a bug'],
'text' => ['type' => 'plaint_text', 'text' => 'By proceeding I confirm I\'ve read the guidelines.'],
'confirm' => ['type' => 'plaint_text', 'text' => 'Proceed'],
'deny' => ['type' => 'plaint_text', 'text' => 'Go back to reading']
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean plain_text?

]
);

$slackOptions = (new SlackOptions())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,31 @@ public function testCanBeInstantiated()
$actions->button('first button text', 'https://example.org', null, 'test-value')
->button('second button text', 'https://example.org/slack', 'danger')
->button('third button text', null, null, 'test-value-3')
->button(
'fourth button text',
null,
null,
'test-value-4',
[
'title' => [
'type' => 'plain_text',
'text' => 'test-confirm-title-4',
],
'text' => [
'type' => 'plain_text',
'text' => 'test-confirm-text-4',
],
'confirm' => [
'type' => 'plain_text',
'text' => 'test-confirm-confirm-4',
],
'deny' => [
'type' => 'plain_text',
'text' => 'test-confirm-deny-4',
],
'style' => 'danger',
]
)
;

$this->assertSame([
Expand Down Expand Up @@ -53,6 +78,33 @@ public function testCanBeInstantiated()
],
'value' => 'test-value-3',
],
[
'type' => 'button',
'text' => [
'type' => 'plain_text',
'text' => 'fourth button text',
],
'value' => 'test-value-4',
'confirm' => [
'title' => [
'type' => 'plain_text',
'text' => 'test-confirm-title-4',
],
'text' => [
'type' => 'plain_text',
'text' => 'test-confirm-text-4',
],
'confirm' => [
'type' => 'plain_text',
'text' => 'test-confirm-confirm-4',
],
'deny' => [
'type' => 'plain_text',
'text' => 'test-confirm-deny-4',
],
'style' => 'danger',
],
],
],
], $actions->toArray());
}
Expand Down