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