public function onBeforeInit()
    {
        // Theme is not yet defined properly at this time
        /* @var $request SS_HttpRequest */
        $request = $this->owner->getRequest();
        $url = $request->getURL();
        if (strpos($url, 'dev/build') === 0) {
            return;
        }
        if ($this->isAdminBackend()) {
            $member = Member::currentUser();
            // Silverstripe does not redirect if invalid login to the /admin section so layout will be broken
            if ($member && $member->ID) {
                if (class_exists('Subsite')) {
                    Subsite::$disable_subsite_filter = true;
                }
                $access = Permission::checkMember($member, 'CMS_ACCESS');
                if (class_exists('Subsite')) {
                    Subsite::$disable_subsite_filter = false;
                }
                if (!$access) {
                    $uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : Director::baseURL();
                    Session::set("Security.Message.message", _t('Security.ALREADYLOGGEDIN'));
                    Session::set("Security.Message.type", 'warning');
                    Session::set("BackURL", $uri);
                    Session::save();
                    header('Location:' . Director::absoluteBaseURL() . '/Security/login' . "?BackURL=" . urlencode($uri));
                    exit;
                }
            }
            return;
        }
        $conf = $this->config();
        if ($iframe = $request->getVar('iframe')) {
            if (!$iframe || $iframe == 'disabled') {
                Cookie::force_expiry('iframe');
            } else {
                Cookie::set('iframe', true);
            }
        }
        $outdated = $conf->outdated_browser;
        if ($outdated && $outdated['enabled']) {
            if (Director::isDev()) {
                ThemeHeadRequirements::javascript(THEME_FRAMEWORK_PATH . '/javascript/outdatedbrowser/outdatedbrowser.js');
                Requirements::css(THEME_FRAMEWORK_PATH . '/javascript/outdatedbrowser/outdatedbrowser.css');
            } else {
                ThemeHeadRequirements::javascript(THEME_FRAMEWORK_PATH . '/javascript/outdatedbrowser/outdatedbrowser.min.js');
                Requirements::css(THEME_FRAMEWORK_PATH . '/javascript/outdatedbrowser/outdatedbrowser.min.css');
            }
            ThemeHeadRequirements::javascriptTemplate(THEME_FRAMEWORK_PATH . '/javascript/outdated.js', array('BgColor' => $outdated['bg_color'], 'Color' => $outdated['color'], 'LowerThan' => $outdated['lower_than'], 'Lang' => i18n::get_lang_from_locale(i18n::get_locale())));
        }
        if ($conf->include_jquery) {
            FormExtraJquery::include_jquery();
        }
        if ($conf->include_jquery_ui) {
            FormExtraJquery::include_jquery_ui();
        }
        $uikit = $conf->uikit;
        if ($uikit && $uikit['enabled']) {
            $uikitTheme = 'uikit';
            if ($uikit['theme']) {
                $uikitTheme .= '.' . $uikit['theme'];
            }
            $uikitComponents = $uikit['components'];
            if (Director::isDev()) {
                Requirements::javascript(THEME_FRAMEWORK_PATH . '/uikit/js/uikit.js');
                if ($uikit['theme_enabled']) {
                    Requirements::css(THEME_FRAMEWORK_PATH . '/uikit/css/' . $uikitTheme . '.css');
                }
                foreach ($uikitComponents as $component) {
                    Requirements::javascript(THEME_FRAMEWORK_PATH . '/uikit/js/components/' . $component . '.js');
                    if ($uikit['theme_enabled']) {
                        $componentTheme = '';
                        if ($uikit['theme']) {
                            $componentTheme = '.' . $uikit['theme'];
                        }
                        Requirements::css(THEME_FRAMEWORK_PATH . '/uikit/css/components/' . $component . $componentTheme . '.css');
                    }
                }
            } else {
                Requirements::javascript(THEME_FRAMEWORK_PATH . '/uikit/js/uikit.min.js');
                if ($uikit['theme_enabled']) {
                    Requirements::css(THEME_FRAMEWORK_PATH . '/uikit/css/' . $uikitTheme . '.min.css');
                }
                foreach ($uikitComponents as $component) {
                    Requirements::javascript(THEME_FRAMEWORK_PATH . '/uikit/js/components/' . $component . '.min.js');
                    if ($uikit['theme_enabled']) {
                        $componentTheme = '';
                        if ($uikit['theme']) {
                            $componentTheme = '.' . $uikit['theme'];
                        }
                        Requirements::css(THEME_FRAMEWORK_PATH . '/uikit/css/components/' . $component . $componentTheme . '.min.css');
                    }
                }
            }
            // If we loaded notify
            if (in_array('notify', $uikitComponents)) {
                if ($this->owner->hasMethod('SessionMessage') && $this->owner->SessionMessage(false)) {
                    $this->sessionMessage = $message = $this->owner->SessionMessage();
                    $content = Convert::raw2js($message->Content);
                    $type = Convert::raw2js($message->Type);
                    // Convert default Silverstripe types
                    switch ($type) {
                        case self::MESSAGE_BAD:
                            $type = self::NOTIFY_DANGER;
                            break;
                        case self::MESSAGE_GOOD:
                            $type = self::NOTIFY_SUCCESS;
                            break;
                        case self::MESSAGE_WARNING:
                            $type = self::NOTIFY_WARNING;
                            break;
                        case self::MESSAGE_INFO:
                            $type = self::NOTIFY_INFO;
                            break;
                    }
                    Requirements::customScript(<<<JS
UIkit.notify('{$content}',{
  status: '{$type}',
  timeout: 0
});
JS
);
                }
            }
        }
        $noty = $conf->noty;
        if ($noty && $noty['enabled']) {
            if (Director::isDev()) {
                Requirements::javascript(THEME_FRAMEWORK_PATH . '/javascript/noty/packaged/jquery.noty.packaged.js');
            } else {
                Requirements::javascript(THEME_FRAMEWORK_PATH . '/javascript/noty/packaged/jquery.noty.packaged.min.js');
            }
            $theme = $noty['theme'];
            $layout = $noty['layout'];
            Requirements::css(THEME_FRAMEWORK_PATH . '/javascript/noty/themes/' . $theme . '.css');
            Requirements::customScript(<<<JS
jQuery.extend(jQuery.noty.defaults,{
  theme: '{$theme}',
  layout: '{$layout}',
  closeWith: ['click','button']
});
JS
);
            // Flash messages
            if ($this->owner->hasMethod('SessionMessage') && $this->owner->SessionMessage(false)) {
                $this->sessionMessage = $message = $this->owner->SessionMessage();
                $content = Convert::raw2js($message->Content);
                $type = Convert::raw2js($message->Type);
                // Convert default Silverstripe types
                switch ($type) {
                    case self::MESSAGE_BAD:
                        $type = self::NOTY_ERROR;
                        break;
                    case self::MESSAGE_GOOD:
                        $type = self::NOTY_SUCCESS;
                        break;
                    case self::MESSAGE_WARNING:
                        $type = self::NOTY_ALERT;
                        break;
                    case self::MESSAGE_INFO:
                        $type = self::NOTY_INFO;
                        break;
                }
                Requirements::customScript(<<<JS
noty({
  text: '{$content}',
  type: '{$type}',
  timeout: false
});
JS
);
            }
        }
        // Forcing js to bottom allow to put some scripts tags in the head if we want to
        Requirements::set_force_js_to_bottom(true);
    }
 public function HeadScripts()
 {
     return ThemeHeadRequirements::output();
 }