Skip to content

Commit

Permalink
feature #36154 [Notifier][Slack] Add fields on Slack Section block (b…
Browse files Browse the repository at this point in the history
…irkof)

This PR was merged into the 5.1-dev branch.

Discussion
----------

[Notifier][Slack] Add fields on Slack Section block

| Q             | A
| ------------- | ---
| Branch?       | master <!-- see below -->
| Bug fix?      | no
| New feature?  | yes <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tickets       |  <!-- prefix each issue number with "Fix #", if any -->
| License       | MIT
| Doc PR        | <!-- required for new features -->
<!--
Replace this notice by a short README for your feature/bugfix. This will help people
understand your PR and can be used as a start for the documentation.

Additionally (see https://symfony.com/releases):
 - Always add tests and ensure they pass.
 - Never break backward compatibility (see https://symfony.com/bc).
 - Bug fixes must be submitted against the lowest maintained branch where they apply
   (lowest branches are regularly merged to upper ones so they get the fixes too.)
 - Features and deprecations must be submitted against branch master.
-->
Added `fields` field on section block.
> An array of text objects. Any text objects included with fields will be rendered in a compact format that allows for 2 columns of side-by-side text. Maximum number of items is 10. Maximum length for the text in each item is 2000 characters.

Example of use:
```
$slackOptions = (new SlackOptions())
            ->block((new SlackSectionBlock())->text('My message'))
            ->block(new SlackDividerBlock())
            ->block(
                (new SlackSectionBlock())
                    ->field('*Max Rating*')
                    ->field('5.0')
                    ->field('*Min Rating*')
                    ->field('1.0')
            );
```

Expected output:

<img width="677" alt="Screen Shot 2020-03-21 at 09 57 36" src="https://user-images.githubusercontent.com/65848/77222314-b8360c80-6b5a-11ea-874c-2cfb1829f839.png">

Commits
-------

faad197 Added fields on Slack Section block
  • Loading branch information
fabpot committed Mar 23, 2020
2 parents 0c22ab8 + faad197 commit 0076ed5
Showing 1 changed file with 13 additions and 0 deletions.
Expand Up @@ -34,6 +34,19 @@ public function text(string $text, bool $markdown = true): self
return $this;
}

/**
* @return $this
*/
public function field(string $text, bool $markdown = true): self
{
$this->options['fields'][] = [
'type' => $markdown ? 'mrkdwn' : 'plain_text',
'text' => $text,
];

return $this;
}

/**
* @return $this
*/
Expand Down

0 comments on commit 0076ed5

Please sign in to comment.