Install Back Office dashboard home path

Edit on GitHub

This document explains how to configure the Back Office to redirect users to /dashboard as the default landing page after login, replacing the default Spryker home path.

Prerequisites

Install the following features:

NAME REQUIRED VERSION INTEGRATION GUIDE
Spryker Core Back Office 202602.0 Install the Spryker Core Back Office feature
SecurityGui 202602.0 Install the Spryker Core feature
SecurityOauthUser 202602.0 -

Install or update the required modules using Composer:

composer require spryker/application:"^3.46.0" spryker/gui:"^4.12.0" spryker/security-oauth-user:"^1.0.0"
Verification

Make sure the following modules have been installed:

MODULE MINIMUM VERSION EXPECTED DIRECTORY
Application 3.46.0 vendor/spryker/application
Gui 4.12.0 vendor/spryker/gui
SecurityOauthUser 1.0.0 vendor/spryker/security-oauth-user

1) Set up configuration

  1. Create or update src/Pyz/Zed/Application/ApplicationConfig.php to redirect the Back Office index action to /dashboard:

src/Pyz/Zed/Application/ApplicationConfig.php

<?php

declare(strict_types = 1);

namespace Pyz\Zed\Application;

use Spryker\Zed\Application\ApplicationConfig as SprykerApplicationConfig;

class ApplicationConfig extends SprykerApplicationConfig
{
    protected const string INDEX_ACTION_REDIRECT_URL = '/dashboard';

    /**
     * @return string|null
     */
    public function getIndexActionRedirectUrl(): ?string
    {
        return static::INDEX_ACTION_REDIRECT_URL;
    }
}
  1. Update src/Pyz/Zed/Gui/GuiConfig.php to set /dashboard as the navigation home path:

src/Pyz/Zed/Gui/GuiConfig.php

<?php

namespace Pyz\Zed\Gui;

use Spryker\Zed\Gui\GuiConfig as SprykerGuiConfig;

class GuiConfig extends SprykerGuiConfig
{
    protected const string HOME_PATH = '/dashboard';
}
  1. Update src/Pyz/Zed/SecurityGui/SecurityGuiConfig.php to redirect users to /dashboard after password-based login:

src/Pyz/Zed/SecurityGui/SecurityGuiConfig.php

<?php

namespace Pyz\Zed\SecurityGui;

use Spryker\Zed\SecurityGui\SecurityGuiConfig as SprykerSecurityGuiConfig;

class SecurityGuiConfig extends SprykerSecurityGuiConfig
{
    protected const string HOME_PATH = '/dashboard';
}
  1. If your project uses OAuth-based login, create src/Pyz/Zed/SecurityOauthUser/SecurityOauthUserConfig.php:

src/Pyz/Zed/SecurityOauthUser/SecurityOauthUserConfig.php

<?php

declare(strict_types = 1);

namespace Pyz\Zed\SecurityOauthUser;

use Spryker\Zed\SecurityOauthUser\SecurityOauthUserConfig as SprykerSecurityOauthUserConfig;

class SecurityOauthUserConfig extends SprykerSecurityOauthUserConfig
{
    protected const string HOME_PATH = '/dashboard';
}
Verification

Log in to the Back Office. Make sure you are redirected to /dashboard after a successful login.

2) Set up behavior

Enable the following behavior by registering the plugins:

PLUGIN SPECIFICATION PREREQUISITES NAMESPACE
HomePathTwigPlugin Exposes the homePath Twig variable so Back Office templates can render the correct home link URL. - Spryker\Zed\Gui\Communication\Plugin\Twig

src/Pyz/Zed/Twig/TwigDependencyProvider.php

<?php

namespace Pyz\Zed\Twig;

use Spryker\Zed\Gui\Communication\Plugin\Twig\HomePathTwigPlugin;
use Spryker\Zed\Twig\TwigDependencyProvider as SprykerTwigDependencyProvider;

class TwigDependencyProvider extends SprykerTwigDependencyProvider
{
    /**
     * @return array<\Spryker\Shared\TwigExtension\Dependency\Plugin\TwigPluginInterface>
     */
    protected function getTwigPlugins(): array
    {
        return [
            new HomePathTwigPlugin(),
        ];
    }
}
Verification

In the Back Office, click the Spryker logo or any home navigation link. Make sure you are redirected to /dashboard.