Ease rendering individual labels
authorMatthias Schmidt <gravatronics@live.com>
Sun, 24 May 2020 11:50:31 +0000 (13:50 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Sun, 24 May 2020 11:50:31 +0000 (13:50 +0200)
Close #3331

com.woltlab.wcf/templates/__labelFormField.tpl
com.woltlab.wcf/templates/__labelSelection.tpl
com.woltlab.wcf/templates/article.tpl
com.woltlab.wcf/templates/articleAdd.tpl
com.woltlab.wcf/templates/articleListItems.tpl
wcfsetup/install/files/acp/templates/__labelFormField.tpl
wcfsetup/install/files/acp/templates/articleAdd.tpl
wcfsetup/install/files/acp/templates/articleList.tpl
wcfsetup/install/files/lib/data/label/Label.class.php

index 90bde6516f307ddc3b32f678cdb75cd9f26470ec..6ce59f485a920d906e8ccde184c8b6a368bb8d3b 100644 (file)
@@ -7,7 +7,7 @@
                        <ul class="scrollableDropdownMenu">
                                {foreach from=$field->getLabelGroup() item=label}
                                        <li data-label-id="{@$label->labelID}">
-                                               <span><span class="badge label{if $label->getClassNames()} {@$label->getClassNames()}{/if}">{$label->getTitle()}</span></span>
+                                               <span>{@$label->render()}</span>
                                        </li>
                                {/foreach}
                        </ul>
index e8ff3d2c4378f79ccc898c5fe5981089b17c44d8..81b4884a7478679e3dd9c37cdf79c6c4de607703 100644 (file)
@@ -8,7 +8,7 @@
                                        <div class="dropdownMenu">
                                                <ul class="scrollableDropdownMenu">
                                                        {foreach from=$labelGroup item=label}
-                                                               <li data-label-id="{@$label->labelID}"><span><span class="badge label{if $label->getClassNames()} {@$label->getClassNames()}{/if}">{$label->getTitle()}</span></span></li>
+                                                               <li data-label-id="{@$label->labelID}"><span>{@$label->render()}</span></li>
                                                        {/foreach}
                                                </ul>
                                        </div>
index b84c63f62bb5373323301f0e8bbd827c92f98ae9..0f116773286d8f026932cf1c0cc14c4e987e2f97 100644 (file)
@@ -12,7 +12,7 @@
                                                <span class="icon icon16 fa-tags"></span>
                                                <ul class="labelList">
                                                        {foreach from=$article->getLabels() item=label}
-                                                               <li><span class="label badge{if $label->getClassNames()} {$label->getClassNames()}{/if}">{$label->getTitle()}</span></li>
+                                                               <li>{@$label->render()}</li>
                                                        {/foreach}
                                                </ul>
                                        </li>
index e026cc5c154183932a5ae143a73f31fd5bd07088..b3bdb7cc575d519fe8adb52cbec11538c959891b 100644 (file)
                                                                        <div class="dropdownMenu">
                                                                                <ul class="scrollableDropdownMenu">
                                                                                        {foreach from=$labelGroup item=label}
-                                                                                               <li data-label-id="{@$label->labelID}"><span><span class="badge label{if $label->getClassNames()} {@$label->getClassNames()}{/if}">{$label->getTitle()}</span></span></li>
+                                                                                               <li data-label-id="{@$label->labelID}"><span>{@$label->render()}</span></li>
                                                                                        {/foreach}
                                                                                </ul>
                                                                        </div>
index 52ee0194bd3d939a585f8f16d0979305407681fc..dab3340756cc2e93efc1991320e596d529a959ee 100644 (file)
@@ -22,7 +22,7 @@
                                        {if $article->hasLabels()}
                                                <div class="contentItemLabels">
                                                        {foreach from=$article->getLabels() item=label}
-                                                               <span class="label badge contentItemLabel{if $label->getClassNames()} {$label->getClassNames()}{/if}">{$label->getTitle()}</span>
+                                                               {@$label->render('contentItemLabel')}
                                                        {/foreach}
                                                </div>
                                        {/if}
index 90bde6516f307ddc3b32f678cdb75cd9f26470ec..6ce59f485a920d906e8ccde184c8b6a368bb8d3b 100644 (file)
@@ -7,7 +7,7 @@
                        <ul class="scrollableDropdownMenu">
                                {foreach from=$field->getLabelGroup() item=label}
                                        <li data-label-id="{@$label->labelID}">
-                                               <span><span class="badge label{if $label->getClassNames()} {@$label->getClassNames()}{/if}">{$label->getTitle()}</span></span>
+                                               <span>{@$label->render()}</span>
                                        </li>
                                {/foreach}
                        </ul>
index e026cc5c154183932a5ae143a73f31fd5bd07088..b3bdb7cc575d519fe8adb52cbec11538c959891b 100644 (file)
                                                                        <div class="dropdownMenu">
                                                                                <ul class="scrollableDropdownMenu">
                                                                                        {foreach from=$labelGroup item=label}
-                                                                                               <li data-label-id="{@$label->labelID}"><span><span class="badge label{if $label->getClassNames()} {@$label->getClassNames()}{/if}">{$label->getTitle()}</span></span></li>
+                                                                                               <li data-label-id="{@$label->labelID}"><span>{@$label->render()}</span></li>
                                                                                        {/foreach}
                                                                                </ul>
                                                                        </div>
index d9d4c904c28d8f3eb466eb31e67f7b5ea5becd53..aeb7a29d7e1e6f2f8b7c529780ccb2fdd81fe3e3 100644 (file)
                                                                        {if $article->hasLabels()}
                                                                                <ul class="labelList" style="float: right; padding-left: 7px;">
                                                                                        {foreach from=$article->getLabels() item=label}
-                                                                                               <li><span class="badge label{if $label->getClassNames()} {$label->getClassNames()}{/if}">{$label->getTitle()}</span></li>
+                                                                                               <li>{@$label->render()}</li>
                                                                                        {/foreach}
                                                                                </ul>
                                                                        {/if}
index 2d63925f876bbd4296e31ad304e3eec8e9722c7a..dbfbe56584709b85b45219fe66c28dcf9362113e 100644 (file)
@@ -3,6 +3,7 @@ namespace wcf\data\label;
 use wcf\data\DatabaseObject;
 use wcf\system\request\IRouteController;
 use wcf\system\WCF;
+use wcf\util\StringUtil;
 
 /**
  * Represents a label.
@@ -48,4 +49,17 @@ class Label extends DatabaseObject implements IRouteController {
                
                return $this->cssClassName;
        }
+       
+       /**
+        * Returns the HTML representation of the label.
+        * 
+        * @param       string          $additionalClasses
+        * @return      string
+        * @since       5.3
+        */
+       public function render($additionalClasses = '') {
+               return '<span class="badge label' . ($this->getClassNames() ? ' ' . $this->getClassNames() : '')
+                       . ($additionalClasses ? ' ' . $additionalClasses : '') . '">'
+                       . StringUtil::encodeHTML($this->getTitle()) . '</span>';
+       }
 }