forked from maknz/slack
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Timepicker element * Restrict plain_text_input to input block types * Support plain_text_input dispatch config * Additional select blocks and improved block hierarchy * Add unit tests for new block types * Rename existing Select classes to StaticSelect
- Loading branch information
Showing
45 changed files
with
3,297 additions
and
670 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
namespace Maknz\Slack\BlockElement; | ||
|
||
use Maknz\Slack\PlaceholderTrait; | ||
|
||
abstract class AbstractDynamicSelect extends Confirmable | ||
{ | ||
use PlaceholderTrait; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,178 +1,9 @@ | ||
<?php | ||
namespace Maknz\Slack\BlockElement; | ||
|
||
use InvalidArgumentException; | ||
use Maknz\Slack\Object\OptionGroup; | ||
|
||
abstract class AbstractSelect extends Options | ||
/** | ||
* @deprecated This class is deprecated in favour of AbstractStaticSelect since 2.2.0 and will be removed in a future release. | ||
*/ | ||
abstract class AbstractSelect extends AbstractStaticSelect | ||
{ | ||
/** | ||
* Select placeholder. | ||
* | ||
* @var \Maknz\Slack\BlockElement\Text | ||
*/ | ||
protected $placeholder; | ||
|
||
/** | ||
* Select option groups. | ||
* | ||
* @var \Maknz\Slack\Object\OptionGroup[] | ||
*/ | ||
protected $option_groups = []; | ||
|
||
/** | ||
* Get the placeholder. | ||
* | ||
* @return \Maknz\Slack\BlockElement\Text | ||
*/ | ||
public function getPlaceholder() | ||
{ | ||
return $this->placeholder; | ||
} | ||
|
||
/** | ||
* Set the placeholder. | ||
* | ||
* @param mixed $placeholder | ||
* | ||
* @return $this | ||
* | ||
* @throws \InvalidArgumentException | ||
*/ | ||
public function setPlaceholder($placeholder) | ||
{ | ||
$this->placeholder = Text::create($placeholder, Text::TYPE_PLAIN); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Set options available within the block. | ||
* | ||
* @param array $options | ||
* | ||
* @return $this | ||
* | ||
* @throws \InvalidArgumentException | ||
*/ | ||
public function setOptions(array $options) | ||
{ | ||
$this->clearOptionGroups(); | ||
|
||
return parent::setOptions($options); | ||
} | ||
|
||
/** | ||
* Add an option to the block. | ||
* | ||
* @param mixed $option | ||
* | ||
* @return $this | ||
* | ||
* @throws \InvalidArgumentException | ||
*/ | ||
public function addOption($option) | ||
{ | ||
parent::addOption($option); | ||
$this->clearOptionGroups(); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Get the option groups. | ||
* | ||
* @return \Maknz\Slack\Object\OptionGroup[] | ||
*/ | ||
public function getOptionGroups() | ||
{ | ||
return $this->option_groups; | ||
} | ||
|
||
/** | ||
* Get the option groups in array format. | ||
* | ||
* @return array | ||
*/ | ||
public function getOptionGroupsAsArrays() | ||
{ | ||
$groups = []; | ||
|
||
foreach ($this->getOptionGroups() as $group) { | ||
$groups[] = $group->toArray(); | ||
} | ||
|
||
return $groups; | ||
} | ||
|
||
/** | ||
* Set the option groups. | ||
* | ||
* @param array $groups | ||
* | ||
* @return $this | ||
* | ||
* @throws \InvalidArgumentException | ||
*/ | ||
public function setOptionGroups(array $groups) | ||
{ | ||
$this->clearOptions(); | ||
$this->clearOptionGroups(); | ||
|
||
foreach ($groups as $group) { | ||
$this->addOptionGroup($group); | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Clear option groups in the block. | ||
* | ||
* @return $this | ||
*/ | ||
public function clearOptionGroups() | ||
{ | ||
$this->option_groups = []; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Clear options and option groups. | ||
* | ||
* @return $this | ||
*/ | ||
public function clearAllOptions() | ||
{ | ||
$this->clearOptions(); | ||
$this->clearOptionGroups(); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Add an option group to the block. | ||
* | ||
* @param mixed $group | ||
* | ||
* @return $this | ||
* | ||
* @throws \InvalidArgumentException | ||
*/ | ||
public function addOptionGroup($group) | ||
{ | ||
if (is_array($group)) { | ||
$group = new OptionGroup($group); | ||
} | ||
|
||
if ($group instanceof OptionGroup) { | ||
$this->clearOptions(); | ||
$this->option_groups[] = $group; | ||
|
||
return $this; | ||
} | ||
|
||
throw new InvalidArgumentException('The option group must be an instance of '.OptionGroup::class.' or a keyed array'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
<?php | ||
namespace Maknz\Slack\BlockElement; | ||
|
||
use InvalidArgumentException; | ||
use Maknz\Slack\Object\OptionGroup; | ||
use Maknz\Slack\PlaceholderTrait; | ||
|
||
abstract class AbstractStaticSelect extends Options | ||
{ | ||
use PlaceholderTrait; | ||
|
||
/** | ||
* Select option groups. | ||
* | ||
* @var \Maknz\Slack\Object\OptionGroup[] | ||
*/ | ||
protected $option_groups = []; | ||
|
||
/** | ||
* Set options available within the block. | ||
* | ||
* @param array $options | ||
* | ||
* @return $this | ||
* | ||
* @throws \InvalidArgumentException | ||
*/ | ||
public function setOptions(array $options) | ||
{ | ||
$this->clearOptionGroups(); | ||
|
||
return parent::setOptions($options); | ||
} | ||
|
||
/** | ||
* Add an option to the block. | ||
* | ||
* @param mixed $option | ||
* | ||
* @return $this | ||
* | ||
* @throws \InvalidArgumentException | ||
*/ | ||
public function addOption($option) | ||
{ | ||
parent::addOption($option); | ||
$this->clearOptionGroups(); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Get the option groups. | ||
* | ||
* @return \Maknz\Slack\Object\OptionGroup[] | ||
*/ | ||
public function getOptionGroups() | ||
{ | ||
return $this->option_groups; | ||
} | ||
|
||
/** | ||
* Get the option groups in array format. | ||
* | ||
* @return array | ||
*/ | ||
public function getOptionGroupsAsArrays() | ||
{ | ||
$groups = []; | ||
|
||
foreach ($this->getOptionGroups() as $group) { | ||
$groups[] = $group->toArray(); | ||
} | ||
|
||
return $groups; | ||
} | ||
|
||
/** | ||
* Set the option groups. | ||
* | ||
* @param array $groups | ||
* | ||
* @return $this | ||
* | ||
* @throws \InvalidArgumentException | ||
*/ | ||
public function setOptionGroups(array $groups) | ||
{ | ||
$this->clearOptions(); | ||
$this->clearOptionGroups(); | ||
|
||
foreach ($groups as $group) { | ||
$this->addOptionGroup($group); | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Clear option groups in the block. | ||
* | ||
* @return $this | ||
*/ | ||
public function clearOptionGroups() | ||
{ | ||
$this->option_groups = []; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Clear options and option groups. | ||
* | ||
* @return $this | ||
*/ | ||
public function clearAllOptions() | ||
{ | ||
$this->clearOptions(); | ||
$this->clearOptionGroups(); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Add an option group to the block. | ||
* | ||
* @param mixed $group | ||
* | ||
* @return $this | ||
* | ||
* @throws \InvalidArgumentException | ||
*/ | ||
public function addOptionGroup($group) | ||
{ | ||
if (is_array($group)) { | ||
$group = new OptionGroup($group); | ||
} | ||
|
||
if ($group instanceof OptionGroup) { | ||
$this->clearOptions(); | ||
$this->option_groups[] = $group; | ||
|
||
return $this; | ||
} | ||
|
||
throw new InvalidArgumentException('The option group must be an instance of '.OptionGroup::class.' or a keyed array'); | ||
} | ||
} |
Oops, something went wrong.