Skip to content

Commit

Permalink
Migrate custom notices to <woltlab-core-notice>
Browse files Browse the repository at this point in the history
  • Loading branch information
BurntimeX committed Nov 17, 2023
1 parent 500147c commit 8e0295b
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 31 deletions.
30 changes: 21 additions & 9 deletions com.woltlab.wcf/templates/userNotice.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,27 @@
{hascontent}
{content}
{foreach from=$__wcf->getNoticeHandler()->getVisibleNotices() item='notice'}
<div class="{$notice->cssClassName} notice{if $notice->isDismissible} noticeDismissible active{/if}" role="status">
{if $notice->isDismissible}
<button type="button" class="jsDismissNoticeButton jsTooltip" data-object-id="{$notice->noticeID}" title="{lang}wcf.notice.button.dismiss{/lang}">
{icon name='xmark'}
</button>
{/if}

{@$notice}
</div>
{if $notice->isCustom()}
<div class="{$notice->cssClassName} notice{if $notice->isDismissible} noticeDismissible active{/if}" role="status">
{if $notice->isDismissible}
<button type="button" class="jsDismissNoticeButton jsTooltip" data-object-id="{$notice->noticeID}" title="{lang}wcf.notice.button.dismiss{/lang}">
{icon name='xmark'}
</button>
{/if}

{@$notice}
</div>
{else}
<woltlab-core-notice type="{$notice->cssClassName}" class="notice{if $notice->isDismissible} noticeDismissible active{/if}">
{if $notice->isDismissible}
<button type="button" class="jsDismissNoticeButton jsTooltip" data-object-id="{$notice->noticeID}" title="{lang}wcf.notice.button.dismiss{/lang}">
{icon name='xmark'}
</button>
{/if}

{@$notice}
</woltlab-core-notice>
{/if}
{/foreach}
{/content}

Expand Down
9 changes: 4 additions & 5 deletions wcfsetup/install/files/acp/templates/noticeAdd.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,11 @@
<dt><label for="cssClassName">{lang}wcf.acp.notice.cssClassName{/lang}</label></dt>
<dd>
{foreach from=$availableCssClassNames item=className}
{if $className == 'custom'}
<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>
{else}
<label><input type="radio" name="cssClassName" value="{$className}"{if $cssClassName == $className} checked{/if}> <span>{lang}wcf.acp.notice.cssClassName.{$className}{/lang}</span></label>
{/if}
<label><input type="radio" name="cssClassName" value="{$className}"{if $cssClassName == $className} checked{/if}> <span>{lang}wcf.acp.notice.cssClassName.{$className}{/lang}</span></label>
{/foreach}

<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>

{if $errorField == 'cssClassName'}
<small class="innerError">
{if $errorType == 'empty'}
Expand Down
20 changes: 4 additions & 16 deletions wcfsetup/install/files/lib/acp/form/NoticeAddForm.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace wcf\acp\form;

use wcf\data\notice\Notice;
use wcf\data\notice\NoticeAction;
use wcf\data\notice\NoticeEditor;
use wcf\data\object\type\ObjectType;
Expand Down Expand Up @@ -29,19 +30,6 @@ class NoticeAddForm extends AbstractForm
*/
public $activeMenuItem = 'wcf.acp.menu.link.notice.add';

/**
* list pf pre-defined CSS class names
* @var string[]
*/
public $availableCssClassNames = [
'info',
'success',
'warning',
'error',

'custom',
];

/**
* name of the chosen CSS class name
* @var string
Expand Down Expand Up @@ -106,7 +94,7 @@ public function assignVariables()

WCF::getTPL()->assign([
'action' => 'add',
'availableCssClassNames' => $this->availableCssClassNames,
'availableCssClassNames' => Notice::TYPES,
'cssClassName' => $this->cssClassName,
'customCssClassName' => $this->customCssClassName,
'isDisabled' => $this->isDisabled,
Expand Down Expand Up @@ -297,15 +285,15 @@ public function validate()
// validate class name
if (empty($this->cssClassName)) {
throw new UserInputException('cssClassName');
} elseif (!\in_array($this->cssClassName, $this->availableCssClassNames)) {
throw new UserInputException('cssClassName', 'invalid');
} elseif ($this->cssClassName == 'custom') {
if (empty($this->cssClassName)) {
throw new UserInputException('cssClassName');
}
if (!Regex::compile('^-?[_a-zA-Z]+[_a-zA-Z0-9-]+$')->match($this->customCssClassName)) {
throw new UserInputException('cssClassName', 'invalid');
}
} elseif (!\in_array($this->cssClassName, Notice::TYPES)) {
throw new UserInputException('cssClassName', 'invalid');
}

foreach ($this->groupedConditionObjectTypes as $groupedObjectTypes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function readData()
I18nHandler::getInstance()->setOptions('notice', 1, $this->notice->notice, 'wcf.notice.notice.notice\d+');

$this->cssClassName = $this->notice->cssClassName;
if (!\in_array($this->cssClassName, $this->availableCssClassNames)) {
if (!\in_array($this->cssClassName, Notice::TYPES)) {
$this->customCssClassName = $this->cssClassName;
$this->cssClassName = 'custom';
}
Expand Down
15 changes: 15 additions & 0 deletions wcfsetup/install/files/lib/data/notice/Notice.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
*/
class Notice extends DatabaseObject implements IRouteController
{
/**
* Available notice types.
* @var string[]
* @since 6.1
*/
const TYPES = ['info', 'success', 'warning', 'error'];

/**
* true if the active user has dismissed the notice
* @var bool
Expand Down Expand Up @@ -127,4 +134,12 @@ public function isDismissed()

return $this->isDismissed;
}

/**
* @since 6.1
*/
public function isCustom(): bool
{
return !\in_array($this->cssClassName, self::TYPES);
}
}

0 comments on commit 8e0295b

Please sign in to comment.