Skip to content

Commit 3fb2a14

Browse files
committed
IBX-6554: Added null checks to prevent errors in LocationVoter and Twig templates
1 parent b9a9153 commit 3fb2a14

File tree

3 files changed

+38
-32
lines changed

3 files changed

+38
-32
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11502,12 +11502,6 @@ parameters:
1150211502
count: 1
1150311503
path: src/lib/Menu/Voter/LocationVoter.php
1150411504

11505-
-
11506-
message: '#^Cannot access property \$id on Ibexa\\Contracts\\Core\\Repository\\Values\\Content\\Location\|null\.$#'
11507-
identifier: property.nonObject
11508-
count: 1
11509-
path: src/lib/Menu/Voter/LocationVoter.php
11510-
1151111505
-
1151211506
message: '#^Call to an undefined method Symfony\\Component\\HttpFoundation\\Session\\SessionInterface\:\:getFlashBag\(\)\.$#'
1151311507
identifier: method.notFound

src/bundle/Resources/views/themes/admin/content/location_view.html.twig

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
{% block breadcrumbs %}
3939
{% set items = [] %}
40-
{% for path_location in path_locations %}
40+
{% for path_location in path_locations ?? [] %}
4141
{% if not loop.last %}
4242
{% set items = items|merge([{
4343
'value': ibexa_content_name(path_location.contentInfo),
@@ -55,13 +55,19 @@
5555
{% endblock %}
5656

5757
{% block context_menu %}
58-
{% set content_sidebar_right = location is defined and location is not null
59-
? knp_menu_get('ezplatform_admin_ui.menu.content.sidebar_right', [], {'location': location, 'content': content, 'content_type': content_type})
60-
: [] %}
61-
{{ knp_menu_render(content_sidebar_right, {'template': '@ibexadesign/ui/menu/context_menu.html.twig'}) }}
58+
{% if location is defined and location is not null %}
59+
{% set content_sidebar_right = knp_menu_get('ezplatform_admin_ui.menu.content.sidebar_right', [], {
60+
'location': location,
61+
'content': content,
62+
'content_type': content_type
63+
}) %}
64+
{{ knp_menu_render(content_sidebar_right, {'template': '@ibexadesign/ui/menu/context_menu.html.twig'}) }}
65+
{% endif %}
6266

6367
<div class="ibexa-extra-actions-container">
64-
{% include '@ibexadesign/content/widget/content_create.html.twig' with {'form': form_content_create, content } only %}
68+
{% if form_content_create is defined %}
69+
{% include '@ibexadesign/content/widget/content_create.html.twig' with {'form': form_content_create, content } only %}
70+
{% endif %}
6571
{% if form_content_edit is defined and form_user_edit is not defined %}
6672
{% include '@ibexadesign/content/widget/content_edit.html.twig' with {'form': form_content_edit} only %}
6773
{% endif %}
@@ -78,10 +84,18 @@
7884
{% if form_user_delete is defined %}
7985
{% include '@ibexadesign/content/modal/user_delete.html.twig' with {'form': form_user_delete} only %}
8086
{% endif %}
81-
{{ form(form_location_copy, {'action': path('ibexa.location.copy')}) }}
82-
{{ form(form_location_move, {'action': path('ibexa.location.move')}) }}
83-
{{ form(form_location_copy_subtree, {'action': path('ibexa.location.copy_subtree')}) }}
84-
{{ form(form_content_visibility_update, {'action': path('ibexa.content.update_visibility')}) }}
87+
{% if form_location_copy is defined %}
88+
{{ form(form_location_copy, {'action': path('ibexa.location.copy')}) }}
89+
{% endif %}
90+
{% if form_location_move is defined %}
91+
{{ form(form_location_move, {'action': path('ibexa.location.move')}) }}
92+
{% endif %}
93+
{% if form_location_copy_subtree is defined %}
94+
{{ form(form_location_copy_subtree, {'action': path('ibexa.location.copy_subtree')}) }}
95+
{% endif %}
96+
{% if form_content_visibility_update is defined %}
97+
{{ form(form_content_visibility_update, {'action': path('ibexa.content.update_visibility')}) }}
98+
{% endif %}
8599
{% endblock %}
86100

87101
{% block header %}
@@ -168,9 +182,9 @@
168182
</div>
169183
</div>
170184
</div>
171-
{% if content_has_reverse_relations and location is defined and location is not null and not location.contentInfo.isHidden %}
172-
{% include '@ibexadesign/content/modal/hide_confirmation.html.twig' %}
173-
{% endif %}
185+
{% if content_has_reverse_relations is defined and content_has_reverse_relations and location is defined and location is not null and not location.contentInfo.isHidden %}
186+
{% include '@ibexadesign/content/modal/hide_confirmation.html.twig' %}
187+
{% endif %}
174188
</div>
175189
{% endblock %}
176190

src/lib/Menu/Voter/LocationVoter.php

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,13 @@ class LocationVoter implements VoterInterface
1717
{
1818
private const CONTENT_VIEW_ROUTE_NAME = 'ibexa.content.view';
1919

20-
/**
21-
* @var \Symfony\Component\HttpFoundation\RequestStack
22-
*/
23-
private $requestStack;
24-
25-
/**
26-
* @param \Symfony\Component\HttpFoundation\RequestStack $requestStack
27-
*/
20+
private RequestStack $requestStack;
21+
2822
public function __construct(RequestStack $requestStack)
2923
{
3024
$this->requestStack = $requestStack;
3125
}
3226

33-
/**
34-
* {@inheritdoc}
35-
*/
3627
public function matchItem(ItemInterface $item): ?bool
3728
{
3829
$routes = $item->getExtra('routes', []);
@@ -43,8 +34,15 @@ public function matchItem(ItemInterface $item): ?bool
4334
$contentView = $request->attributes->get('view');
4435
$locationId = $route['parameters']['locationId'];
4536

46-
if ($contentView instanceof ContentView && in_array($locationId, $contentView->getLocation()->path ?? [$contentView->getLocation()->id])) {
47-
return true;
37+
if ($contentView instanceof ContentView) {
38+
$location = $contentView->getLocation();
39+
if ($location !== null) {
40+
$path = $location->path ?? [$location->id];
41+
42+
if (in_array($locationId, $path, true)) {
43+
return true;
44+
}
45+
}
4846
}
4947
}
5048
}

0 commit comments

Comments
 (0)