Skip to content

Commit c69101f

Browse files
author
Ante Prkacin
committed
NGSTACK-991 update logic in 'VisibilityInfo' controller for determining if location is hidden and update message text
1 parent 45604da commit c69101f

File tree

2 files changed

+37
-19
lines changed

2 files changed

+37
-19
lines changed

bundle/Controller/Content/VisibilityInfo.php

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,44 +28,61 @@ public function __invoke(int $contentId, Request $request): Response
2828

2929
if ($content->getContentInfo()->isHidden() === true) {
3030
$title = $this->translator->trans('content.visibility.content_hidden', [], 'locationview');
31-
} else {
32-
try {
33-
$locations = $this->locationService->loadLocations($content->getContentInfo());
31+
}
32+
33+
try {
34+
$locations = $this->locationService->loadLocations($content->getContentInfo());
3435

35-
$hiddenLocations = 0;
36-
foreach ($locations as $location) {
37-
if ($location->explicitlyHidden || $location->invisible) {
38-
$hiddenLocations++;
39-
}
36+
$hiddenLocations = 0;
37+
$hiddenByAncestor = false;
38+
foreach ($locations as $location) {
39+
if ($location->explicitlyHidden) {
40+
$hiddenLocations++;
41+
continue;
4042
}
4143

42-
if ($hiddenLocations !== 0) {
43-
if (count($locations) === 1) {
44-
$title = $this->translator->trans('content.visibility.location_hidden', [], 'locationview');
45-
} else {
46-
$title = $this->translator->trans(
44+
if ($location->isInvisible() && $location->getParentLocation()?->isInvisible()) {
45+
$hiddenLocations++;
46+
$hiddenByAncestor = true;
47+
}
48+
}
49+
50+
if ($hiddenLocations !== 0) {
51+
if (count($locations) === 1) {
52+
$extraContent = $this->translator->trans('content.visibility.location_hidden', [], 'locationview');
53+
} else {
54+
$extraContent = $hiddenByAncestor
55+
? $this->translator->trans(
56+
'content.visibility.locations_hidden_by_ancestor',
57+
[
58+
'%hidden%' => $hiddenLocations,
59+
'%total%' => count($locations),
60+
],
61+
'locationview',
62+
)
63+
: $this->translator->trans(
4764
'content.visibility.locations_hidden',
4865
[
4966
'%hidden%' => $hiddenLocations,
5067
'%total%' => count($locations),
5168
],
5269
'locationview',
5370
);
54-
}
5571
}
56-
} catch (BadStateException $e) {
57-
$title = $this->translator->trans('content.visibility.cannot_fetch_locations', [], 'locationview');
5872
}
73+
} catch (BadStateException $e) {
74+
$extraContent = $this->translator->trans('content.visibility.cannot_fetch_locations', [], 'locationview');
5975
}
6076

61-
if (!isset($title)) {
77+
if (!isset($title) && !isset($extraContent)) {
6278
return new Response('', Response::HTTP_NO_CONTENT);
6379
}
6480

6581
return $this->render('@IbexaAdminUi/themes/admin/ui/component/alert/alert.html.twig',
6682
[
6783
'type' => 'info',
68-
'title' => $title,
84+
'title' => $title ?? '',
85+
'extra_content' => $extraContent ?? '',
6986
'icon_path' => $iconPath,
7087
'class' => 'mt-4',
7188
],

bundle/Resources/translations/locationview.en.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ content.last_modified: "Last modified"
88

99
content.visibility.content_hidden: "Content is hidden"
1010
content.visibility.location_hidden: "Location is hidden"
11-
content.visibility.locations_hidden: "Locations: %hidden% out of %total% hidden"
11+
content.visibility.locations_hidden: "%hidden% of %total% location(s) are hidden"
12+
content.visibility.locations_hidden_by_ancestor: "%hidden% of %total% location(s) are hidden by parent or ancestor location"
1213
content.visibility.cannot_fetch_locations: "Can't fetch locations for this content!"

0 commit comments

Comments
 (0)