Skip to content

Commit 40163d7

Browse files
authored
Merge pull request #5711 from WoltLab/custom-notices
Migrate custom notices to `<woltlab-core-notice>`
2 parents 53ca3fd + 8e0295b commit 40163d7

File tree

5 files changed

+45
-31
lines changed

5 files changed

+45
-31
lines changed

com.woltlab.wcf/templates/userNotice.tpl

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,27 @@
2727
{hascontent}
2828
{content}
2929
{foreach from=$__wcf->getNoticeHandler()->getVisibleNotices() item='notice'}
30-
<div class="{$notice->cssClassName} notice{if $notice->isDismissible} noticeDismissible active{/if}" role="status">
31-
{if $notice->isDismissible}
32-
<button type="button" class="jsDismissNoticeButton jsTooltip" data-object-id="{$notice->noticeID}" title="{lang}wcf.notice.button.dismiss{/lang}">
33-
{icon name='xmark'}
34-
</button>
35-
{/if}
36-
37-
{@$notice}
38-
</div>
30+
{if $notice->isCustom()}
31+
<div class="{$notice->cssClassName} notice{if $notice->isDismissible} noticeDismissible active{/if}" role="status">
32+
{if $notice->isDismissible}
33+
<button type="button" class="jsDismissNoticeButton jsTooltip" data-object-id="{$notice->noticeID}" title="{lang}wcf.notice.button.dismiss{/lang}">
34+
{icon name='xmark'}
35+
</button>
36+
{/if}
37+
38+
{@$notice}
39+
</div>
40+
{else}
41+
<woltlab-core-notice type="{$notice->cssClassName}" class="notice{if $notice->isDismissible} noticeDismissible active{/if}">
42+
{if $notice->isDismissible}
43+
<button type="button" class="jsDismissNoticeButton jsTooltip" data-object-id="{$notice->noticeID}" title="{lang}wcf.notice.button.dismiss{/lang}">
44+
{icon name='xmark'}
45+
</button>
46+
{/if}
47+
48+
{@$notice}
49+
</woltlab-core-notice>
50+
{/if}
3951
{/foreach}
4052
{/content}
4153

wcfsetup/install/files/acp/templates/noticeAdd.tpl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,11 @@
7878
<dt><label for="cssClassName">{lang}wcf.acp.notice.cssClassName{/lang}</label></dt>
7979
<dd>
8080
{foreach from=$availableCssClassNames item=className}
81-
{if $className == 'custom'}
82-
<label><input type="radio" name="cssClassName" value="custom"{if $cssClassName == 'custom'} checked{/if}> <span><input type="text" id="customCssClassName" name="customCssClassName" value="{$customCssClassName}" class="medium"></span></label>
83-
{else}
84-
<label><input type="radio" name="cssClassName" value="{$className}"{if $cssClassName == $className} checked{/if}> <span>{lang}wcf.acp.notice.cssClassName.{$className}{/lang}</span></label>
85-
{/if}
81+
<label><input type="radio" name="cssClassName" value="{$className}"{if $cssClassName == $className} checked{/if}> <span>{lang}wcf.acp.notice.cssClassName.{$className}{/lang}</span></label>
8682
{/foreach}
83+
84+
<label><input type="radio" name="cssClassName" value="custom"{if $cssClassName == 'custom'} checked{/if}> <span><input type="text" id="customCssClassName" name="customCssClassName" value="{$customCssClassName}" class="medium"></span></label>
85+
8786
{if $errorField == 'cssClassName'}
8887
<small class="innerError">
8988
{if $errorType == 'empty'}

wcfsetup/install/files/lib/acp/form/NoticeAddForm.class.php

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace wcf\acp\form;
44

5+
use wcf\data\notice\Notice;
56
use wcf\data\notice\NoticeAction;
67
use wcf\data\notice\NoticeEditor;
78
use wcf\data\object\type\ObjectType;
@@ -29,19 +30,6 @@ class NoticeAddForm extends AbstractForm
2930
*/
3031
public $activeMenuItem = 'wcf.acp.menu.link.notice.add';
3132

32-
/**
33-
* list pf pre-defined CSS class names
34-
* @var string[]
35-
*/
36-
public $availableCssClassNames = [
37-
'info',
38-
'success',
39-
'warning',
40-
'error',
41-
42-
'custom',
43-
];
44-
4533
/**
4634
* name of the chosen CSS class name
4735
* @var string
@@ -106,7 +94,7 @@ public function assignVariables()
10694

10795
WCF::getTPL()->assign([
10896
'action' => 'add',
109-
'availableCssClassNames' => $this->availableCssClassNames,
97+
'availableCssClassNames' => Notice::TYPES,
11098
'cssClassName' => $this->cssClassName,
11199
'customCssClassName' => $this->customCssClassName,
112100
'isDisabled' => $this->isDisabled,
@@ -297,15 +285,15 @@ public function validate()
297285
// validate class name
298286
if (empty($this->cssClassName)) {
299287
throw new UserInputException('cssClassName');
300-
} elseif (!\in_array($this->cssClassName, $this->availableCssClassNames)) {
301-
throw new UserInputException('cssClassName', 'invalid');
302288
} elseif ($this->cssClassName == 'custom') {
303289
if (empty($this->cssClassName)) {
304290
throw new UserInputException('cssClassName');
305291
}
306292
if (!Regex::compile('^-?[_a-zA-Z]+[_a-zA-Z0-9-]+$')->match($this->customCssClassName)) {
307293
throw new UserInputException('cssClassName', 'invalid');
308294
}
295+
} elseif (!\in_array($this->cssClassName, Notice::TYPES)) {
296+
throw new UserInputException('cssClassName', 'invalid');
309297
}
310298

311299
foreach ($this->groupedConditionObjectTypes as $groupedObjectTypes) {

wcfsetup/install/files/lib/acp/form/NoticeEditForm.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function readData()
7070
I18nHandler::getInstance()->setOptions('notice', 1, $this->notice->notice, 'wcf.notice.notice.notice\d+');
7171

7272
$this->cssClassName = $this->notice->cssClassName;
73-
if (!\in_array($this->cssClassName, $this->availableCssClassNames)) {
73+
if (!\in_array($this->cssClassName, Notice::TYPES)) {
7474
$this->customCssClassName = $this->cssClassName;
7575
$this->cssClassName = 'custom';
7676
}

wcfsetup/install/files/lib/data/notice/Notice.class.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@
2828
*/
2929
class Notice extends DatabaseObject implements IRouteController
3030
{
31+
/**
32+
* Available notice types.
33+
* @var string[]
34+
* @since 6.1
35+
*/
36+
const TYPES = ['info', 'success', 'warning', 'error'];
37+
3138
/**
3239
* true if the active user has dismissed the notice
3340
* @var bool
@@ -127,4 +134,12 @@ public function isDismissed()
127134

128135
return $this->isDismissed;
129136
}
137+
138+
/**
139+
* @since 6.1
140+
*/
141+
public function isCustom(): bool
142+
{
143+
return !\in_array($this->cssClassName, self::TYPES);
144+
}
130145
}

0 commit comments

Comments
 (0)