From ef127c8b57898c4c1bc1d8a9daa45cd450eebb84 Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Wed, 22 Nov 2023 13:43:10 +0100 Subject: [PATCH 1/2] Add a form node for showing notices --- .../form/builder/NoticeFormNode.class.php | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 wcfsetup/install/files/lib/system/form/builder/NoticeFormNode.class.php diff --git a/wcfsetup/install/files/lib/system/form/builder/NoticeFormNode.class.php b/wcfsetup/install/files/lib/system/form/builder/NoticeFormNode.class.php new file mode 100644 index 00000000000..3b00aa4b996 --- /dev/null +++ b/wcfsetup/install/files/lib/system/form/builder/NoticeFormNode.class.php @@ -0,0 +1,45 @@ + + * @since 6.1 + */ +class NoticeFormNode extends LanguageItemFormNode +{ + const AVAILABLE_TYPES = ['info', 'success', 'warning', 'error']; + + protected string $type = 'info'; + + /** + * @inheritDoc + */ + public function getHtml() + { + return '' . parent::getHtml() . ''; + } + + /** + * Sets the type of this notice. + */ + public function type(string $type): static + { + if (!\in_array($type, self::AVAILABLE_TYPES)) { + throw new \BadMethodCallException("Invalid value '{$type}' given."); + } + + $this->type = $type; + + return $this; + } + + public function getType(): string + { + return $this->type; + } +} From 830bc124191eb520f1d73224dd486bc61bd5251c Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Wed, 22 Nov 2023 14:39:10 +0100 Subject: [PATCH 2/2] Use an enum for the notice type --- .../form/builder/NoticeFormNode.class.php | 14 +++------ .../form/builder/NoticeFormNodeType.class.php | 29 +++++++++++++++++++ 2 files changed, 33 insertions(+), 10 deletions(-) create mode 100644 wcfsetup/install/files/lib/system/form/builder/NoticeFormNodeType.class.php diff --git a/wcfsetup/install/files/lib/system/form/builder/NoticeFormNode.class.php b/wcfsetup/install/files/lib/system/form/builder/NoticeFormNode.class.php index 3b00aa4b996..19fa232bf99 100644 --- a/wcfsetup/install/files/lib/system/form/builder/NoticeFormNode.class.php +++ b/wcfsetup/install/files/lib/system/form/builder/NoticeFormNode.class.php @@ -12,33 +12,27 @@ */ class NoticeFormNode extends LanguageItemFormNode { - const AVAILABLE_TYPES = ['info', 'success', 'warning', 'error']; - - protected string $type = 'info'; + protected NoticeFormNodeType $type = NoticeFormNodeType::Info; /** * @inheritDoc */ public function getHtml() { - return '' . parent::getHtml() . ''; + return '' . parent::getHtml() . ''; } /** * Sets the type of this notice. */ - public function type(string $type): static + public function type(NoticeFormNodeType $type): static { - if (!\in_array($type, self::AVAILABLE_TYPES)) { - throw new \BadMethodCallException("Invalid value '{$type}' given."); - } - $this->type = $type; return $this; } - public function getType(): string + public function getType(): NoticeFormNodeType { return $this->type; } diff --git a/wcfsetup/install/files/lib/system/form/builder/NoticeFormNodeType.class.php b/wcfsetup/install/files/lib/system/form/builder/NoticeFormNodeType.class.php new file mode 100644 index 00000000000..77133ee7cf9 --- /dev/null +++ b/wcfsetup/install/files/lib/system/form/builder/NoticeFormNodeType.class.php @@ -0,0 +1,29 @@ + + * @since 6.1 + */ +enum NoticeFormNodeType +{ + case Info; + case Success; + case Warning; + case Error; + + public function toString(): string + { + return match ($this) { + self::Info => 'info', + self::Success => 'success', + self::Warning => 'warning', + self::Error => 'error', + }; + } +}