Gdn_Plugin::autoToggle PHP Method

autoToggle() public method

Automatically handle the toggle effect.
Deprecation:
public autoToggle ( object $Sender, mixed $Redirect = null )
$Sender object Reference to the invoking controller
$Redirect mixed
    public function autoToggle($Sender, $Redirect = null)
    {
        deprecated('Gdn_Plugin->autoToggle()');
        $PluginName = $this->getPluginIndex();
        $EnabledKey = "Plugins.{$PluginName}.Enabled";
        $CurrentConfig = c($EnabledKey, false);
        $PassedKey = val(1, $Sender->RequestArgs);
        if ($Sender->Form->authenticatedPostBack() || Gdn::session()->validateTransientKey($PassedKey)) {
            $CurrentConfig = !$CurrentConfig;
            SaveToConfig($EnabledKey, $CurrentConfig);
        }
        if ($Sender->Form->authenticatedPostBack()) {
            $this->controller_index($Sender);
        } else {
            if ($Redirect === false) {
                return $CurrentConfig;
            }
            if (is_null($Redirect)) {
                Redirect('plugin/' . strtolower($PluginName));
            } else {
                Redirect($Redirect);
            }
        }
        return $CurrentConfig;
    }