Grav\Plugin\AdminPlugin::setup PHP Method

setup() public method

If the admin path matches, initialize the Login plugin configuration and set the admin as active.
public setup ( )
    public function setup()
    {
        // Autoloader
        spl_autoload_register(function ($class) {
            if (Utils::startsWith($class, 'Grav\\Plugin\\Admin')) {
                require_once __DIR__ . '/classes/' . strtolower(basename(str_replace("\\", "/", $class))) . '.php';
            }
        });
        $route = $this->config->get('plugins.admin.route');
        if (!$route) {
            return;
        }
        $this->base = '/' . trim($route, '/');
        $this->admin_route = rtrim($this->grav['pages']->base(), '/') . $this->base;
        $this->uri = $this->grav['uri'];
        // check for existence of a user account
        $account_dir = $file_path = $this->grav['locator']->findResource('account://');
        $user_check = glob($account_dir . '/*.yaml');
        // If no users found, go to register
        if ($user_check == false || count((array) $user_check) == 0) {
            if (!$this->isAdminPath()) {
                $this->grav->redirect($this->admin_route);
            }
            $this->template = 'register';
        }
        // Only activate admin if we're inside the admin path.
        if ($this->isAdminPath()) {
            $this->active = true;
            // Set cache based on admin_cache option
            if (method_exists($this->grav['cache'], 'setEnabled')) {
                $this->grav['cache']->setEnabled($this->config->get('plugins.admin.cache_enabled'));
            }
        }
    }