Skip to content

Commit 3a9ae4a

Browse files
author
Ante Prkacin
committed
NGSTACK-991 add info about locations visibility to adminUI content full view
1 parent dc5e0c1 commit 3a9ae4a

File tree

4 files changed

+87
-0
lines changed

4 files changed

+87
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Netgen\Bundle\IbexaAdminUIExtraBundle\Controller\Content;
6+
7+
use Ibexa\Contracts\AdminUi\Controller\Controller;
8+
use Ibexa\Contracts\Core\Repository\Exceptions\BadStateException;
9+
use Ibexa\Contracts\Core\Repository\LocationService;
10+
use Ibexa\Contracts\Core\Repository\Values\Content\Content;
11+
use Symfony\Component\HttpFoundation\Response;
12+
13+
class VisibilityInfo extends Controller
14+
{
15+
public function __construct(
16+
private readonly LocationService $locationService,
17+
) {}
18+
19+
public function __invoke(Content $content): Response
20+
{
21+
$info = 'Content is HIDDEN';
22+
$messageType = 'error';
23+
if ($content->getContentInfo()->isHidden() === false) {
24+
try {
25+
$locations = $this->locationService->loadLocations($content->getContentInfo());
26+
27+
$hiddenLocations = 0;
28+
foreach ($locations as $location) {
29+
if ($location->explicitlyHidden || $location->invisible) {
30+
$hiddenLocations++;
31+
}
32+
}
33+
34+
if (count($locations) === 1) {
35+
if ($hiddenLocations === 0) {
36+
$info = 'Location: VISIBLE';
37+
$messageType = 'success';
38+
} else {
39+
$info = 'Location: HIDDEN';
40+
}
41+
} else if ($hiddenLocations === 0) {
42+
$info = 'Locations: ALL VISIBLE';
43+
$messageType = 'success';
44+
} else {
45+
// some or all locations are hidden
46+
$info = sprintf(
47+
'Locations: %s out of %s HIDDEN',
48+
$hiddenLocations,
49+
count($locations),
50+
);
51+
if (count($locations) !== $hiddenLocations) {
52+
$messageType = 'warning';
53+
}
54+
}
55+
} catch (BadStateException $e) {
56+
$info = "Can't fetch locations for this content!";
57+
}
58+
}
59+
60+
return $this->render(
61+
'@NetgenIbexaAdminUIExtra/themes/ngadmin/ui/visibility_info.html.twig',
62+
[
63+
'info' => $info,
64+
'type' => $messageType,
65+
],
66+
);
67+
}
68+
}

bundle/Resources/config/services/controllers.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ services:
77
- '@Netgen\Bundle\IbexaAdminUIExtraBundle\Form\FormFactory'
88
- '@Ibexa\Core\Helper\TranslationHelper'
99

10+
Netgen\Bundle\IbexaAdminUIExtraBundle\Controller\Content\VisibilityInfo:
11+
parent: Ibexa\Contracts\AdminUi\Controller\Controller
12+
arguments:
13+
- '@ibexa.api.service.location'
14+
1015
Netgen\Bundle\IbexaAdminUIExtraBundle\Controller\Content\LastModifiedInfo:
1116
parent: Ibexa\Contracts\AdminUi\Controller\Controller
1217

bundle/Resources/views/themes/ngadmin/content/location_view.html.twig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@
4343
{{ render(controller('Netgen\\Bundle\\IbexaAdminUIExtraBundle\\Controller\\Content\\LastModifiedInfo', {
4444
'content': content,
4545
})) }}
46+
47+
{{ render(controller('Netgen\\Bundle\\IbexaAdminUIExtraBundle\\Controller\\Content\\VisibilityInfo', {
48+
'content': content,
49+
})) }}
4650
</div>
4751
</div>
4852
</div>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<div>
2+
{% embed '@IbexaAdminUi/themes/admin/ui/component/alert/alert.html.twig' with {
3+
type: type,
4+
} %}
5+
{% block icon %}{% endblock %}
6+
{% block title %}
7+
<div class="ibexa-alert__title">{{ info }}</div>
8+
{% endblock %}
9+
{% endembed %}
10+
</div>

0 commit comments

Comments
 (0)