Add option to invert the logic in toggle action
authorMarcel Werk <burntime@woltlab.com>
Tue, 10 Dec 2024 16:24:27 +0000 (17:24 +0100)
committerMarcel Werk <burntime@woltlab.com>
Tue, 10 Dec 2024 16:24:27 +0000 (17:24 +0100)
wcfsetup/install/files/lib/system/gridView/action/ToggleAction.class.php

index 57f8224479c18bbd7061d36e94b8987e8d6d84ae..fc07fa5e1a01ec8496f898ecbabff80064fb6feb 100644 (file)
@@ -24,6 +24,7 @@ class ToggleAction extends AbstractAction
         private readonly string $enableEndpoint,
         private readonly string $disableEndpoint,
         private readonly string $propertyName = 'isDisabled',
+        private readonly bool $propertyIsDisabledState = true,
         ?Closure $isAvailableCallback = null
     ) {
         parent::__construct($isAvailableCallback);
@@ -44,7 +45,8 @@ class ToggleAction extends AbstractAction
         );
 
         $ariaLabel = WCF::getLanguage()->get('wcf.global.button.enable');
-        $checked = !$row->{$this->propertyName} ? 'checked' : '';
+        $checked = (!$row->{$this->propertyName} && $this->propertyIsDisabledState)
+            || ($row->{$this->propertyName} && !$this->propertyIsDisabledState) ? 'checked' : '';
 
         return <<<HTML
             <woltlab-core-toggle-button aria-label="{$ariaLabel}" data-enable-endpoint="{$enableEndpoint}" data-disable-endpoint="{$disableEndpoint}" {$checked}></woltlab-core-toggle-button>