setController($controller); if (!$fields) { $fields = $this->getFormFields(); } if (!$actions) { $actions = $this->getFormActions(); } parent::__construct($controller, $name, $fields, $actions); $this->setFormAction(Security::logout_url()); } /** * Build the FieldList for the logout form * * @return FieldList */ protected function getFormFields() { $fields = FieldList::create(); $controller = $this->getController(); $backURL = $controller->getBackURL() ?: $controller->getReturnReferer(); // Protect against infinite redirection back to the logout URL after logging out if (!$backURL || Director::makeRelative($backURL) === $controller->getRequest()->getURL()) { $backURL = Director::baseURL(); } $fields->push(HiddenField::create('BackURL', 'BackURL', $backURL)); return $fields; } /** * Build default logout form action FieldList * * @return FieldList */ protected function getFormActions() { $actions = FieldList::create( FormAction::create('doLogout', _t('SilverStripe\\Security\\Member.BUTTONLOGOUT', "Log out")) ); return $actions; } }