Skip to content

Commit 26f260f

Browse files
committed
IBX-6554: Removed redundant null checks and added validation for missing location in controller
1 parent 3fb2a14 commit 26f260f

File tree

2 files changed

+45
-52
lines changed

2 files changed

+45
-52
lines changed

src/bundle/Controller/ContentViewController.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
use Ibexa\Contracts\Core\Repository\Values\Content\Location;
4242
use Ibexa\Contracts\Core\Repository\Values\Content\VersionInfo;
4343
use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface;
44+
use Ibexa\Core\Base\Exceptions\NotFoundException;
4445
use Ibexa\Core\MVC\Symfony\Locale\UserLanguagePreferenceProviderInterface;
4546
use Ibexa\Core\MVC\Symfony\View\ContentView;
4647
use Symfony\Component\Form\FormFactoryInterface;
@@ -158,6 +159,12 @@ public function __construct(
158159
*/
159160
public function locationViewAction(Request $request, ContentView $view): ContentView
160161
{
162+
$location = $view->getLocation();
163+
if ($location === null || $location->id === null) {
164+
$contentId = $view->getContent()->id ?? 'unknown';
165+
throw new NotFoundException('Location', "content ID {$contentId}");
166+
}
167+
161168
// We should not cache ContentView because we use forms with CSRF tokens in template
162169
// JIRA ref: https://issues.ibexa.co/browse/EZP-28190
163170
$view->setCacheEnabled(false);

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

Lines changed: 38 additions & 52 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,14 +55,12 @@
5555
{% endblock %}
5656

5757
{% block context_menu %}
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 %}
58+
{% set content_sidebar_right = knp_menu_get('ezplatform_admin_ui.menu.content.sidebar_right', [], {
59+
'location': location,
60+
'content': content,
61+
'content_type': content_type
62+
}) %}
63+
{{ knp_menu_render(content_sidebar_right, {'template': '@ibexadesign/ui/menu/context_menu.html.twig'}) }}
6664

6765
<div class="ibexa-extra-actions-container">
6866
{% if form_content_create is defined %}
@@ -84,18 +82,10 @@
8482
{% if form_user_delete is defined %}
8583
{% include '@ibexadesign/content/modal/user_delete.html.twig' with {'form': form_user_delete} only %}
8684
{% endif %}
87-
{% if form_location_copy is defined %}
8885
{{ form(form_location_copy, {'action': path('ibexa.location.copy')}) }}
89-
{% endif %}
90-
{% if form_location_move is defined %}
9186
{{ form(form_location_move, {'action': path('ibexa.location.move')}) }}
92-
{% endif %}
93-
{% if form_location_copy_subtree is defined %}
9487
{{ form(form_location_copy_subtree, {'action': path('ibexa.location.copy_subtree')}) }}
95-
{% endif %}
96-
{% if form_content_visibility_update is defined %}
9788
{{ form(form_content_visibility_update, {'action': path('ibexa.content.update_visibility')}) }}
98-
{% endif %}
9989
{% endblock %}
10090

10191
{% block header %}
@@ -123,48 +113,44 @@
123113
{% endblock %}
124114
{% endembed %}
125115

126-
{% if location is defined and location is not null %}
127-
{% if location.hidden or location.invisible %}
128-
<div class="pb-4">
129-
{% include '@ibexadesign/ui/component/alert/alert.html.twig' with {
130-
type: 'info',
131-
title: 'content.hidden.message'|trans()|desc('This Content item or its Location is hidden.'),
132-
icon_path: ibexa_icon_path('hide'),
133-
class: 'mb-4',
134-
} only %}
135-
</div>
136-
{% endif %}
137-
{{ ibexa_render_component_group(
138-
'admin-ui-location-view-content-alerts',
139-
{
140-
'versionInfo': content.versionInfo,
141-
'location': location,
142-
}
143-
) }}
116+
{% if location.hidden or location.invisible %}
117+
<div class="pb-4">
118+
{% include '@ibexadesign/ui/component/alert/alert.html.twig' with {
119+
type: 'info',
120+
title: 'content.hidden.message'|trans()|desc('This Content item or its Location is hidden.'),
121+
icon_path: ibexa_icon_path('hide'),
122+
class: 'mb-4',
123+
} only %}
124+
</div>
144125
{% endif %}
126+
{{ ibexa_render_component_group(
127+
'admin-ui-location-view-content-alerts',
128+
{
129+
'versionInfo': content.versionInfo,
130+
'location': location,
131+
}
132+
) }}
145133
{% endblock %}
146134

147135
{% block content %}
148136
<div class="align-items-stretch ibexa-main-row">
149137
<div class="ibexa-content-container">
150138
<div class="panel panel-primary">
151139
<div class="panel-body">
152-
{% if location is defined and location is not null %}
153-
{{ ibexa_render_component_group('admin-ui-location-view-tab-groups', {
154-
'content': content,
155-
'location': location,
156-
'contentType': content_type,
157-
'draft_pagination_params': draft_pagination_params,
158-
'reverse_relation_pagination_params': reverse_relation_pagination_params,
159-
'relation_pagination_params': relation_pagination_params,
160-
'custom_urls_pagination_params': custom_urls_pagination_params,
161-
'system_urls_pagination_params': system_urls_pagination_params,
162-
'roles_pagination_params': roles_pagination_params,
163-
'policies_pagination_params': policies_pagination_params,
164-
'is_location_visible': not location.invisible,
165-
'subitems_module': subitems_module,
166-
}) }}
167-
{% endif %}
140+
{{ ibexa_render_component_group('admin-ui-location-view-tab-groups', {
141+
'content': content,
142+
'location': location,
143+
'contentType': content_type,
144+
'draft_pagination_params': draft_pagination_params,
145+
'reverse_relation_pagination_params': reverse_relation_pagination_params,
146+
'relation_pagination_params': relation_pagination_params,
147+
'custom_urls_pagination_params': custom_urls_pagination_params,
148+
'system_urls_pagination_params': system_urls_pagination_params,
149+
'roles_pagination_params': roles_pagination_params,
150+
'policies_pagination_params': policies_pagination_params,
151+
'is_location_visible': not location.invisible,
152+
'subitems_module': subitems_module,
153+
}) }}
168154

169155
{% if content_type.isContainer %}
170156
{{ form_start(form_subitems_content_edit, { 'action': path('ibexa.content.edit'), 'attr': { 'hidden': 'hidden' }}) }}
@@ -182,7 +168,7 @@
182168
</div>
183169
</div>
184170
</div>
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 %}
171+
{% if content_has_reverse_relations and not location.contentInfo.isHidden %}
186172
{% include '@ibexadesign/content/modal/hide_confirmation.html.twig' %}
187173
{% endif %}
188174
</div>

0 commit comments

Comments
 (0)