1 | <?php |
||
2 | namespace Maknz\Slack\BlockElement; |
||
3 | |||
4 | use InvalidArgumentException; |
||
5 | |||
6 | class ChannelsSelect extends RespondableSelect |
||
7 | { |
||
8 | /** |
||
9 | * Block type. |
||
10 | * |
||
11 | * @var string |
||
12 | */ |
||
13 | protected $type = 'channels_select'; |
||
14 | |||
15 | /** |
||
16 | * The initially selected channel. |
||
17 | * |
||
18 | * @var string |
||
19 | */ |
||
20 | protected $initial_channel; |
||
21 | |||
22 | /** |
||
23 | * Internal attribute to property map. |
||
24 | * |
||
25 | * @var array |
||
26 | */ |
||
27 | protected static $availableAttributes = [ |
||
28 | 'placeholder' => 'placeholder', |
||
29 | 'action_id' => 'action_id', |
||
30 | 'initial_channel' => 'initial_channel', |
||
31 | 'confirm' => 'confirm', |
||
32 | 'response_url_enabled' => 'response_url_enabled', |
||
33 | ]; |
||
34 | |||
35 | /** |
||
36 | * Get the initially selected channel. |
||
37 | * |
||
38 | * @return string |
||
39 | */ |
||
40 | 3 | public function getInitialChannel() |
|
41 | { |
||
42 | 3 | return $this->initial_channel; |
|
43 | } |
||
44 | |||
45 | /** |
||
46 | * Set the initially selected channel. |
||
47 | * |
||
48 | * @param string $initialChannel |
||
49 | * |
||
50 | * @return $this |
||
51 | * |
||
52 | * @throws InvalidArgumentException |
||
53 | */ |
||
54 | 3 | public function setInitialChannel($initialChannel) |
|
55 | { |
||
56 | 3 | if (is_string($initialChannel)) { |
|
0 ignored issues
–
show
introduced
by
![]() |
|||
57 | 2 | $this->initial_channel = $initialChannel; |
|
58 | |||
59 | 2 | return $this; |
|
60 | } |
||
61 | |||
62 | 1 | throw new InvalidArgumentException('The initial channel ID must be a string'); |
|
63 | } |
||
64 | |||
65 | /** |
||
66 | * Convert the block to its array representation. |
||
67 | * |
||
68 | * @return array |
||
69 | */ |
||
70 | 1 | public function toArray() |
|
71 | { |
||
72 | 1 | $data = [ |
|
73 | 1 | 'type' => $this->getType(), |
|
74 | 1 | 'placeholder' => $this->getPlaceholder()->toArray(), |
|
75 | 1 | 'action_id' => $this->getActionId(), |
|
76 | ]; |
||
77 | |||
78 | 1 | if ($this->getInitialChannel()) { |
|
79 | 1 | $data['initial_channel'] = $this->getInitialChannel(); |
|
80 | } |
||
81 | |||
82 | 1 | if ($this->getConfirm()) { |
|
83 | 1 | $data['confirm'] = $this->getConfirm()->toArray(); |
|
84 | } |
||
85 | |||
86 | 1 | if ($this->isResponseUrlEnabled()) { |
|
87 | 1 | $data['response_url_enabled'] = true; |
|
88 | } |
||
89 | |||
90 | 1 | return $data; |
|
91 | } |
||
92 | } |
||
93 |