Skip to content

Commit

Permalink
IBX-5854: Added base backoffice path to adminUI config (#860)
Browse files Browse the repository at this point in the history
Co-authored-by: Konrad Oboza <konrad.oboza@ibexa.co>
Co-authored-by: Łukasz Ostafin <ostafin.lucas@gmail.com>
Co-authored-by: Maciej Kobus <maciej.kobus@ez.no>
  • Loading branch information
4 people authored Aug 30, 2023
1 parent 50ccad7 commit c0fd4c8
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/bundle/Resources/config/services/ui_config/common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,7 @@ services:
Ibexa\AdminUi\UI\Config\Provider\BackOfficeLanguage:
tags:
- { name: ibexa.admin_ui.config.provider, key: 'backOfficeLanguage' }

Ibexa\AdminUi\UI\Config\Provider\CurrentBackOfficePath:
tags:
- { name: ibexa.admin_ui.config.provider, key: 'backOfficePath' }
2 changes: 1 addition & 1 deletion src/bundle/Resources/public/js/scripts/adaptive.filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
const cookieValue = isExpanded ? 'true' : 'false';

if (expandedInfoCookieName) {
ibexa.helpers.cookies.setCookie(expandedInfoCookieName, cookieValue);
ibexa.helpers.cookies.setBackOfficeCookie(expandedInfoCookieName, cookieValue);
}
};
const collapse = bootstrap.Collapse.getOrCreateInstance(adaptiveItemsCollapsibleContainer, {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
(function (global, doc, ibexa) {
const { backOfficePath } = ibexa.adminUiConfig;
const setBackOfficeCookie = (name, value, maxAgeDays = 356, path = backOfficePath) => {
setCookie(name, value, maxAgeDays, path);
};
const setCookie = (name, value, maxAgeDays = 356, path = '/') => {
const maxAge = maxAgeDays * 24 * 60 * 60;

Expand All @@ -21,5 +25,6 @@
ibexa.addConfig('helpers.cookies', {
getCookie,
setCookie,
setBackOfficeCookie,
});
})(window, window.document, window.ibexa);
4 changes: 2 additions & 2 deletions src/bundle/Resources/public/js/scripts/sidebar/main.menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
const isSecondLevelMenuCollapsed = secondLevelMenuNode.classList.contains('ibexa-main-menu__navbar--collapsed');
const newMenuWidth = isSecondLevelMenuCollapsed ? SECOND_LEVEL_EXPANDED_WIDTH : SECOND_LEVEL_COLLAPSED_WIDTH;

ibexa.helpers.cookies.setCookie('second_menu_width', newMenuWidth);
ibexa.helpers.cookies.setBackOfficeCookie('second_menu_width', newMenuWidth);
setWidthOfSecondLevelMenu();
};
const parsePopup = (button) => {
Expand Down Expand Up @@ -131,7 +131,7 @@
const resizeValue = secondMenuLevelCurrentWidth + (clientX - resizeStartPositionX);
const newMenuWidth = resizeValue > SECOND_LEVEL_MANUAL_RESIZE_MIN_WIDTH ? resizeValue : SECOND_LEVEL_COLLAPSED_WIDTH;

ibexa.helpers.cookies.setCookie('second_menu_width', newMenuWidth);
ibexa.helpers.cookies.setBackOfficeCookie('second_menu_width', newMenuWidth);
setWidthOfSecondLevelMenu();
};

Expand Down
50 changes: 50 additions & 0 deletions src/lib/UI/Config/Provider/CurrentBackOfficePath.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\AdminUi\UI\Config\Provider;

use Ibexa\Contracts\AdminUi\UI\Config\ProviderInterface;
use Ibexa\Contracts\Core\Repository\Repository;
use Symfony\Component\Routing\RouterInterface;

final class CurrentBackOfficePath implements ProviderInterface
{
private RouterInterface $router;

private Repository $repository;

public function __construct(
RouterInterface $router,
Repository $repository
) {
$this->router = $router;
$this->repository = $repository;
}

public function getConfig(): string
{
/*
* We need base path here, to properly set backoffice cookies only,
* so they do not interfere with front end SiteAccesses.
* Generating route for `/` allows us to make sure that we do not have any additional parameters
* and we get raw path to back office.
* We are not using reverse matchers here as they work in context of current request.
*
* Sudo is used to avoid insufficient permissions on reading root Location.
*/
return $this->repository->sudo(
function (Repository $repository): string {
$routeInfo = $this->router->match('/');
$path = $this->router->generate($routeInfo['_route'], $routeInfo);
$pathInfo = pathinfo($path);

return $pathInfo['dirname'];
}
);
}
}

0 comments on commit c0fd4c8

Please sign in to comment.