Skip to content

Commit 3c7178c

Browse files
authored
Allow custom label object type container titles (#6454)
1 parent b273540 commit 3c7178c

File tree

2 files changed

+20
-48
lines changed

2 files changed

+20
-48
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,13 @@
100100
<div class="section">
101101
{foreach from=$labelObjectTypeContainers item=container}
102102
<dl>
103-
<dt>{lang}wcf.acp.label.container.{$container->getObjectTypeName()}{/lang}</dt>
103+
<dt>{$container->getTitle()}</dt>
104104
<dd>
105105
<ul class="structuredList">
106106
{foreach from=$container item=objectType}
107107
<li class="{if $objectType->isCategory()} category{/if}"{if $objectType->getDepth()} style="padding-left: {$objectType->getDepth() * 20}px"{/if} data-depth="{$objectType->getDepth()}">
108108
<span>{$objectType->getLabel()}</span>
109-
<label><input id="checkbox_{$container->getObjectTypeID()}_{$objectType->getObjectID()}" type="checkbox" name="objectTypes[{$container->getObjectTypeID()}][]" value="{$objectType->getObjectID()}"{if $objectType->getOptionValue()} checked{/if}></label>
109+
<label><input id="checkbox_{$container->objectTypeID}_{$objectType->getObjectID()}" type="checkbox" name="objectTypes[{$container->objectTypeID}][]" value="{$objectType->getObjectID()}"{if $objectType->getOptionValue()} checked{/if}></label>
110110
</li>
111111
{/foreach}
112112
</ul>

wcfsetup/install/files/lib/system/label/object/type/LabelObjectTypeContainer.class.php

Lines changed: 18 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
namespace wcf\system\label\object\type;
44

55
use wcf\data\object\type\ObjectTypeCache;
6+
use wcf\system\WCF;
67

78
/**
8-
* Label object type container.
9+
* This type of container is used to allow the user when editing label groups to specify
10+
* in which sub-areas (e.g., categories or sub-forums) a label group is available.
911
*
1012
* @author Alexander Ebert
1113
* @copyright 2001-2022 WoltLab GmbH
@@ -15,28 +17,16 @@
1517
final class LabelObjectTypeContainer implements \Countable, \Iterator
1618
{
1719
/**
18-
* list of object types
1920
* @var LabelObjectType[]
2021
*/
21-
public array $objectTypes = [];
22+
private array $objectTypes = [];
2223

23-
/**
24-
* object type id
25-
*/
26-
public int $objectTypeID = 0;
27-
28-
/**
29-
* iterator position
30-
*/
3124
private int $position = 0;
3225

33-
/**
34-
* Creates a new LabelObjectTypeContainer object.
35-
*/
36-
public function __construct(int $objectTypeID)
37-
{
38-
$this->objectTypeID = $objectTypeID;
39-
}
26+
public function __construct(
27+
public readonly int $objectTypeID,
28+
public readonly string $title = ''
29+
) {}
4030

4131
/**
4232
* Adds a label object type.
@@ -46,65 +36,47 @@ public function add(LabelObjectType $objectType): void
4636
$this->objectTypes[] = $objectType;
4737
}
4838

49-
/**
50-
* Returns the object type id.
51-
*/
52-
public function getObjectTypeID(): int
39+
public function getObjectTypeName(): string
5340
{
54-
return $this->objectTypeID;
41+
return ObjectTypeCache::getInstance()->getObjectType($this->objectTypeID)->objectType;
5542
}
5643

57-
/**
58-
* Returns the object type name.
59-
*/
60-
public function getObjectTypeName(): string
44+
public function getTitle(): string
6145
{
62-
return ObjectTypeCache::getInstance()->getObjectType($this->getObjectTypeID())->objectType;
46+
return $this->title ?: WCF::getLanguage()->get('wcf.acp.label.container.' . $this->getObjectTypeName());
6347
}
6448

65-
/**
66-
* @inheritDoc
67-
*/
49+
#[\Override]
6850
public function current(): LabelObjectType
6951
{
7052
return $this->objectTypes[$this->position];
7153
}
7254

73-
/**
74-
* @inheritDoc
75-
*/
55+
#[\Override]
7656
public function key(): int
7757
{
7858
return $this->position;
7959
}
8060

81-
/**
82-
* @inheritDoc
83-
*/
61+
#[\Override]
8462
public function next(): void
8563
{
8664
$this->position++;
8765
}
8866

89-
/**
90-
* @inheritDoc
91-
*/
67+
#[\Override]
9268
public function rewind(): void
9369
{
9470
$this->position = 0;
9571
}
9672

97-
/**
98-
* @inheritDoc
99-
*/
73+
#[\Override]
10074
public function valid(): bool
10175
{
10276
return isset($this->objectTypes[$this->position]);
10377
}
10478

105-
/**
106-
* @inheritDoc
107-
*/
79+
#[\Override]
10880
public function count(): int
10981
{
11082
return \count($this->objectTypes);

0 commit comments

Comments
 (0)