Skip to content

Fix RouteBundle issues and disable Show History button #7882

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function generate(RequestContext $requestContext, string $slug, string $l
throw new MissingRequestContextParameterException(RequestAttributeEnum::SITE->value);
}

$site = $currentRequest->attributes->get(RequestAttributeEnum::SITE->value);
$site = $currentRequest->attributes->get(RequestAttributeEnum::SITE->value); // TODO the requestContext should be kept in sync via listener with request attributes

if (!\is_string($site)) {
throw new MissingRequestContextParameterException(RequestAttributeEnum::SITE->value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,27 @@
use Psr\Container\ContainerInterface;
use Sulu\Route\Domain\Exception\MissingRequestContextParameterException;
use Sulu\Route\Domain\Value\RequestAttributeEnum;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\RequestContext;

final class RouteGenerator implements RouteGeneratorInterface
{
public function __construct(
private ContainerInterface $siteRouteGeneratorLocator,
private RequestContext $requestContext,
private RequestStack $requestStack,
) {
}

public function generate(string $slug, ?string $locale = null, ?string $site = null): string
{
if (null === $site) {
$requestSite = $this->requestContext->getParameter(RequestAttributeEnum::SITE->value);

if (!\is_string($requestSite)) {
$requestSite = $this->requestStack->getCurrentRequest()?->attributes->get(RequestAttributeEnum::SITE->value);
}

if (!\is_string($requestSite)) {
throw new MissingRequestContextParameterException(RequestAttributeEnum::SITE->value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public function getDefaults(Route $route): array
'resourceKey' => $resourceKey,
'resourceId' => $resourceId,
'site' => $route->getSite(),
'locale' => $route->getLocale(),
]);

if (null === $targetRoute) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public function loadExtension(array $config, ContainerConfigurator $container, C
->args([
tagged_locator('sulu_route.site_route_generator', 'site', 'getSite'),
new Reference('router.request_context'),
new Reference('request_stack'),
]);

$services->alias(RouteGeneratorInterface::class, 'sulu_route.route_generator')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Sulu\Route\Application\Routing\Generator\SiteRouteGeneratorInterface;
use Sulu\Route\Domain\Exception\MissingRequestContextParameterException;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\RequestContext;

#[CoversClass(RouteGenerator::class)]
Expand Down Expand Up @@ -61,7 +62,7 @@ public function generate(RequestContext $requestContext, string $slug, string $l
});

$this->requestContext = new RequestContext();
$this->routeGenerator = new RouteGenerator($container, $this->requestContext);
$this->routeGenerator = new RouteGenerator($container, $this->requestContext, new RequestStack());
}

public function testGenerate(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Sulu\Route\Domain\Repository\RouteRepositoryInterface;
use Symfony\Bundle\FrameworkBundle\Controller\RedirectController;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpKernel\Exception\GoneHttpException;
use Symfony\Component\Routing\RequestContext;

Expand Down Expand Up @@ -71,7 +72,7 @@ public function generate(RequestContext $requestContext, string $slug, string $l
});

$this->requestContext = new RequestContext();
$this->routeGenerator = new RouteGenerator($container, $this->requestContext);
$this->routeGenerator = new RouteGenerator($container, $this->requestContext, new RequestStack());

$this->routeHistoryDefaultsProvider = new RouteHistoryDefaultsProvider(
$this->routeRepository->reveal(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import React, {Fragment} from 'react';
import {action, observable} from 'mobx';
import {observer} from 'mobx-react';
import {translate} from '../../utils/Translator';
import Button from '../../components/Button';
import Dialog from '../../components/Dialog';
import Loader from '../../components/Loader';
import Overlay from '../../components/Overlay';
Expand Down Expand Up @@ -66,16 +65,16 @@ class ResourceLocatorHistory extends React.Component<Props> {
};

render() {
const {resourceListStore, props} = this;
const {id} = props;
const {resourceListStore} = this;

const historyRoutes = resourceListStore ? resourceListStore.data : [];

return (
<Fragment>
<Button disabled={!id} icon="su-process" onClick={this.handleButtonClick} skin="link">
{translate('sulu_admin.show_history')}
</Button>
{/* TODO Sulu 3.0 does not yet support the Show History controller therefore we disable the button */}
{/*<Button disabled={!id} icon="su-process" onClick={this.handleButtonClick} skin="link">*/}
{/* {translate('sulu_admin.show_history')}*/}
{/*</Button>*/}
<Overlay
confirmText={translate('sulu_admin.ok')}
onClose={this.handleOverlayClose}
Expand Down
Loading
Loading