Skip to content

Commit 4ceef43

Browse files
committed
fix(backend): restore pageCategories init and harden option filtering
1 parent 876d883 commit 4ceef43

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

assets/script.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,3 +354,9 @@ var structureTweaks = function() {
354354
return this;
355355
};
356356
};
357+
358+
$(document).on('rex:ready', function() {
359+
if ($('#rex-structure-tweaks-startartikel-type').length) {
360+
new structureTweaks().pageCategories();
361+
}
362+
});

lib/hide_categories.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,17 +142,26 @@ protected static function getScriptInLinkmap(array $hidden_categories): string
142142
*/
143143
private static function removeCategoryOptions(string $subject, string $select_id, array $hidden_categories): string
144144
{
145-
/** @phpstan-ignore-next-line PHP 8.4 DOM API is available at runtime */
146-
$document = HTMLDocument::createFromString($subject);
145+
try {
146+
/** @phpstan-ignore-next-line PHP 8.4 DOM API is available at runtime */
147+
$document = HTMLDocument::createFromString($subject);
148+
} catch (\Throwable $exception) {
149+
return $subject;
150+
}
147151

148152
$element = $document->getElementById($select_id);
149153
if ($element) {
154+
$optionsToRemove = [];
150155
foreach ($element->getElementsByTagName('option') as $option) {
151156
/** @phpstan-ignore-next-line PHP 8.4 DOM API is available at runtime */
152157
if (in_array((int) $option->getAttribute('value'), $hidden_categories, true)) {
153-
$element->removeChild($option);
158+
$optionsToRemove[] = $option;
154159
}
155160
}
161+
162+
foreach ($optionsToRemove as $option) {
163+
$element->removeChild($option);
164+
}
156165
}
157166

158167
return $document->saveHtml();

0 commit comments

Comments
 (0)