Skip to content

Commit 9e8a1d5

Browse files
committed
The active page must be a multiple selection so that an “or” condition is possible.
1 parent 2a7fcf7 commit 9e8a1d5

File tree

3 files changed

+15
-25
lines changed

3 files changed

+15
-25
lines changed

wcfsetup/install/files/lib/system/condition/type/request/ActivePageRequestConditionType.class.php

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use wcf\system\condition\type\AbstractConditionType;
77
use wcf\system\condition\type\IContextualConditionType;
88
use wcf\system\condition\type\IMigrateConditionType;
9-
use wcf\system\form\builder\field\SingleSelectionFormField;
9+
use wcf\system\form\builder\field\MultipleSelectionFormField;
1010
use wcf\system\request\RequestHandler;
1111

1212
/**
@@ -15,8 +15,8 @@
1515
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
1616
* @since 6.3
1717
*
18-
* @implements IContextualConditionType<string>
19-
* @extends AbstractConditionType<string>
18+
* @implements IContextualConditionType<string[]>
19+
* @extends AbstractConditionType<string[]>
2020
*/
2121
final class ActivePageRequestConditionType extends AbstractConditionType implements IContextualConditionType, IMigrateConditionType
2222
{
@@ -33,19 +33,18 @@ public function getLabel(): string
3333
}
3434

3535
#[\Override]
36-
public function getFormField(string $id): SingleSelectionFormField
36+
public function getFormField(string $id): MultipleSelectionFormField
3737
{
38-
// SelectFormField stores its value as a string,
39-
// so we need to convert it to an integer in the `matches` method.
40-
return SingleSelectionFormField::create($id)
38+
return MultipleSelectionFormField::create($id)
4139
->options((new PageNodeTree())->getNodeList(), true)
40+
->filterable()
4241
->required();
4342
}
4443

4544
#[\Override]
4645
public function matches(): bool
4746
{
48-
return RequestHandler::getInstance()->getActivePageID() === (int)$this->filter;
47+
return \in_array(RequestHandler::getInstance()->getActivePageID(), $this->filter);
4948
}
5049

5150
#[\Override]
@@ -54,18 +53,15 @@ public function migrateConditionData(array &$conditionData): array
5453
$reverseLogic = $conditionData['pageIDs_reverseLogic'] ?? false;
5554
$pageIDs = $conditionData['pageIDs'] ?? [];
5655

57-
if ($reverseLogic || \count($pageIDs) > 1) {
56+
if ($reverseLogic) {
5857
// `NotOnPageRequestConditionType` should migrate the data.
5958
return [];
6059
}
6160

62-
$conditions = [];
63-
foreach ($pageIDs as $pageID) {
64-
$conditions[] = [
65-
'identifier' => $this->getIdentifier(),
66-
'value' => (string)$pageID,
67-
];
68-
}
61+
$conditions[] = [
62+
'identifier' => $this->getIdentifier(),
63+
'value' => \array_map('strval', $pageIDs),
64+
];
6965

7066
unset($conditionData['pageIDs'], $conditionData['pageIDs_reverseLogic']);
7167

wcfsetup/install/files/lib/system/condition/type/request/NotOnPageRequestConditionType.class.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,12 @@ public function migrateConditionData(array &$conditionData): array
5555
$reverseLogic = $conditionData['pageIDs_reverseLogic'] ?? false;
5656
$pageIDs = $conditionData['pageIDs'] ?? [];
5757

58-
if (!$reverseLogic && \count($pageIDs) <= 1) {
58+
if (!$reverseLogic) {
5959
// `ActivePageRequestConditionType` should migrate the data.
6060
return [];
6161
}
6262

6363
$conditions = [];
64-
if (!$reverseLogic) {
65-
// If reverse logic is not activated, we must add all unselected pages.
66-
// This allows us to turn an “or” condition into an “and” condition.
67-
$pageIDs = \array_diff($this->getPageIDs(), $pageIDs);
68-
}
69-
7064
foreach ($pageIDs as $pageID) {
7165
$conditions[] = [
7266
'identifier' => $this->getIdentifier(),

wcfsetup/install/files/lib/system/form/builder/container/condition/ConditionFormContainer.class.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ private function appendCondition(string $identifier, int $index): FormContainer
112112
static function (IFormDocument $document, array $parameters) use ($prefixId, $identifier, $fieldId) {
113113
$conditions = isset($parameters['data'][$prefixId]) ? JSON::decode($parameters['data'][$prefixId]) : [];
114114

115-
if (isset($parameters['data'][$fieldId])) {
115+
if (isset($parameters['data'][$fieldId]) || isset($parameters[$fieldId])) {
116116
$conditions[] = [
117117
"identifier" => $identifier,
118-
"value" => $parameters['data'][$fieldId],
118+
"value" => $parameters['data'][$fieldId] ?? $parameters[$fieldId],
119119
];
120120
}
121121

0 commit comments

Comments
 (0)