Skip to content
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
12 changes: 0 additions & 12 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -11496,18 +11496,6 @@ parameters:
count: 1
path: src/lib/Menu/UserSetting/UserSettingUpdateRightSidebarBuilder.php

-
message: '#^Cannot access property \$attributes on Symfony\\Component\\HttpFoundation\\Request\|null\.$#'
identifier: property.nonObject
count: 1
path: src/lib/Menu/Voter/LocationVoter.php

-
message: '#^Cannot access property \$id on Ibexa\\Contracts\\Core\\Repository\\Values\\Content\\Location\|null\.$#'
identifier: property.nonObject
count: 1
path: src/lib/Menu/Voter/LocationVoter.php

-
message: '#^Call to an undefined method Symfony\\Component\\HttpFoundation\\Session\\SessionInterface\:\:getFlashBag\(\)\.$#'
identifier: method.notFound
Expand Down
9 changes: 8 additions & 1 deletion src/bundle/Controller/ContentViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
use Ibexa\Contracts\Core\Repository\Values\Content\Location;
use Ibexa\Contracts\Core\Repository\Values\Content\VersionInfo;
use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface;
use Ibexa\Core\Base\Exceptions\NotFoundException;
use Ibexa\Core\MVC\Symfony\Locale\UserLanguagePreferenceProviderInterface;
use Ibexa\Core\MVC\Symfony\View\ContentView;
use Symfony\Component\Form\FormFactoryInterface;
Expand Down Expand Up @@ -158,11 +159,17 @@ public function __construct(
*/
public function locationViewAction(Request $request, ContentView $view): ContentView
{
$location = $view->getLocation();
if ($location === null) {
$contentId = $view->getContent()->getId();
throw new NotFoundException('Location', "content ID {$contentId}");
}

// We should not cache ContentView because we use forms with CSRF tokens in template
// JIRA ref: https://issues.ibexa.co/browse/EZP-28190
$view->setCacheEnabled(false);

if (!$view->getContent()->contentInfo->isTrashed()) {
if (!$view->getContent()->getContentInfo()->isTrashed()) {
$this->supplyPathLocations($view);
$this->subitemsContentViewParameterSupplier->supply($view);
$this->supplyContentActionForms($view);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{% set location_path = location.pathString %}

{% extends "@ibexadesign/ui/layout.html.twig" %}

{% trans_default_domain 'ibexa_locationview' %}
Expand Down Expand Up @@ -29,7 +27,7 @@
{{ ibexa_twig_component_group('admin-ui-content-tree-before') }}
<div class="ibexa-content-tree-container"
data-tree-root-location-id="{{ content_tree_module_root|default(ibexa_admin_ui_config['contentTree']['treeRootLocationId']) }}"
data-current-location-path="{{ location_path|default('') }}"
data-current-location-path="{{ location is defined and location is not null ? location.pathString : '' }}"
style="{{ content_tree_width_style }}"
>
<div class="ibexa-content-tree-container__root"></div>
Expand Down Expand Up @@ -57,11 +55,17 @@
{% endblock %}

{% block context_menu %}
{% set content_sidebar_right = knp_menu_get('ezplatform_admin_ui.menu.content.sidebar_right', [], {'location': location, 'content': content, 'content_type': content_type}) %}
{% set content_sidebar_right = knp_menu_get('ezplatform_admin_ui.menu.content.sidebar_right', [], {
'location': location,
'content': content,
'content_type': content_type
}) %}
{{ knp_menu_render(content_sidebar_right, {'template': '@ibexadesign/ui/menu/context_menu.html.twig'}) }}

<div class="ibexa-extra-actions-container">
{% include '@ibexadesign/content/widget/content_create.html.twig' with {'form': form_content_create, content } only %}
{% if form_content_create is defined %}
{% include '@ibexadesign/content/widget/content_create.html.twig' with {'form': form_content_create, content } only %}
{% endif %}
{% if form_content_edit is defined and form_user_edit is not defined %}
{% include '@ibexadesign/content/widget/content_edit.html.twig' with {'form': form_content_edit} only %}
{% endif %}
Expand Down Expand Up @@ -164,9 +168,9 @@
</div>
</div>
</div>
{% if content_has_reverse_relations and not location.contentInfo.isHidden %}
{% include '@ibexadesign/content/modal/hide_confirmation.html.twig' %}
{% endif %}
{% if content_has_reverse_relations and not location.contentInfo.isHidden %}
{% include '@ibexadesign/content/modal/hide_confirmation.html.twig' %}
{% endif %}
</div>
{% endblock %}

Expand Down
37 changes: 18 additions & 19 deletions src/lib/Menu/Voter/LocationVoter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace Ibexa\AdminUi\Menu\Voter;

use Ibexa\Core\MVC\Symfony\View\ContentView;
use Ibexa\Core\Repository\Values\Content\Location;
use Knp\Menu\ItemInterface;
use Knp\Menu\Matcher\Voter\VoterInterface;
use Symfony\Component\HttpFoundation\RequestStack;
Expand All @@ -17,35 +18,33 @@ class LocationVoter implements VoterInterface
{
private const CONTENT_VIEW_ROUTE_NAME = 'ibexa.content.view';

/**
* @var \Symfony\Component\HttpFoundation\RequestStack
*/
private $requestStack;
private RequestStack $requestStack;

/**
* @param \Symfony\Component\HttpFoundation\RequestStack $requestStack
*/
public function __construct(RequestStack $requestStack)
{
$this->requestStack = $requestStack;
}

/**
* {@inheritdoc}
*/
public function matchItem(ItemInterface $item): ?bool
{
$routes = $item->getExtra('routes', []);
foreach ($item->getExtra('routes', []) as $route) {
$routeName = $route['route'] ?? null;
$locationId = isset($route['parameters']['locationId']) ? (int)$route['parameters']['locationId'] : null;

foreach ($routes as $route) {
if (isset($route['route']) && $route['route'] === self::CONTENT_VIEW_ROUTE_NAME) {
$request = $this->requestStack->getCurrentRequest();
$contentView = $request->attributes->get('view');
$locationId = $route['parameters']['locationId'];
if ($routeName !== self::CONTENT_VIEW_ROUTE_NAME || $locationId === null) {
continue;
}

$request = $this->requestStack->getCurrentRequest();
$contentView = $request ? $request->attributes->get('view') : null;
$location = $contentView instanceof ContentView ? $contentView->getLocation() : null;

if (!$location instanceof Location) {
continue;
}

if ($contentView instanceof ContentView && in_array($locationId, $contentView->getLocation()->path ?? [$contentView->getLocation()->id])) {
return true;
}
if (in_array($locationId, array_map('intval', $location->getPath()), true)) {
return true;
}
}

Expand Down
Loading