Skip to content

Commit 883c70d

Browse files
committed
IBX-11487: Refactored backend
1 parent 1fbb200 commit 883c70d

14 files changed

Lines changed: 396 additions & 67 deletions

File tree

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (C) Ibexa AS. All rights reserved.
5+
* @license For full copyright and license information view LICENSE file distributed with this source code.
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace Ibexa\Bundle\AdminUi\Asset;
10+
11+
use Ibexa\Contracts\AdminUi\Rtl\RtlModeResolverInterface;
12+
use Symfony\WebpackEncoreBundle\Asset\EntrypointLookup;
13+
use Symfony\WebpackEncoreBundle\Asset\EntrypointLookupInterface;
14+
use Symfony\WebpackEncoreBundle\Asset\IntegrityDataProviderInterface;
15+
16+
final readonly class RtlEntrypointLookup implements EntrypointLookupInterface, IntegrityDataProviderInterface
17+
{
18+
public function __construct(
19+
private EntrypointLookupInterface $inner,
20+
private RtlModeResolverInterface $rtlModeResolver,
21+
) {
22+
}
23+
24+
/**
25+
* @return array<string>
26+
*/
27+
public function getJavaScriptFiles(string $entryName): array
28+
{
29+
return $this->inner->getJavaScriptFiles($entryName);
30+
}
31+
32+
/**
33+
* @return array<string>
34+
*/
35+
public function getCssFiles(string $entryName): array
36+
{
37+
if ($this->rtlModeResolver->isRtl() && $this->entryExists($entryName . '-rtl')) {
38+
$entryName .= '-rtl';
39+
}
40+
41+
return $this->inner->getCssFiles($entryName);
42+
}
43+
44+
private function entryExists(string $entryName): bool
45+
{
46+
if ($this->inner instanceof EntrypointLookup) {
47+
return $this->inner->entryExists($entryName);
48+
}
49+
50+
return false;
51+
}
52+
53+
/**
54+
* @return array<string, string>
55+
*/
56+
public function getIntegrityData(): array
57+
{
58+
if ($this->inner instanceof IntegrityDataProviderInterface) {
59+
return $this->inner->getIntegrityData();
60+
}
61+
62+
return [];
63+
}
64+
65+
public function reset(): void
66+
{
67+
$this->inner->reset();
68+
}
69+
}

src/bundle/Resources/config/default_parameters.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,4 @@ parameters:
107107

108108
ibexa.dam_widget.folder.content_type_identifier: folder
109109

110-
ibexa.admin_ui.rtl_languages: ['ar', 'he', 'fa', 'ur']
110+
ibexa.admin_ui.rtl_languages: ['ar', 'he', 'fa', 'ur', 'yi', 'iw', 'kd', 'ps']

src/bundle/Resources/config/services/components.yaml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,6 @@ services:
3636
tags:
3737
- { name: twig.extension }
3838

39-
Ibexa\Bundle\AdminUi\Templating\Twig\RtlExtension:
40-
arguments:
41-
$assets: '@assets.packages'
42-
$requestStack: '@request_stack'
43-
$rtlLanguages: '%ibexa.admin_ui.rtl_languages%'
44-
tags:
45-
- { name: twig.extension }
46-
4739
Ibexa\AdminUi\Component\Renderer\DefaultRenderer:
4840
public: false
4941

@@ -55,7 +47,7 @@ services:
5547
$template: '@@ibexadesign/ui/layout_content_after.html.twig'
5648
tags:
5749
- { name: ibexa.twig.component, group: 'admin-ui-layout-content-after' }
58-
50+
5951
Ibexa\AdminUi\Component\EventSubscriber\RenderEventSubscriber:
6052
tags:
6153
- { name: kernel.event_subscriber }

src/bundle/Resources/config/services/services.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,9 @@ services:
1313

1414
Ibexa\Contracts\AdminUi\ContentType\ContentTypeFieldsByExpressionServiceInterface:
1515
'@Ibexa\AdminUi\ContentType\ContentTypeFieldsByExpressionService'
16+
17+
Ibexa\AdminUi\Rtl\RtlModeResolver:
18+
arguments:
19+
$rtlLanguages: '%ibexa.admin_ui.rtl_languages%'
20+
21+
Ibexa\Contracts\AdminUi\Rtl\RtlModeResolverInterface: '@Ibexa\AdminUi\Rtl\RtlModeResolver'

src/bundle/Resources/config/services/twig.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,7 @@ services:
3737
Ibexa\Bundle\AdminUi\Templating\Twig\LocationExtension:
3838
tags:
3939
- { name: twig.extension }
40+
41+
Ibexa\Bundle\AdminUi\Templating\Twig\RtlExtension:
42+
tags:
43+
- { name: twig.extension }

src/bundle/Resources/config/services/ui_config/common.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,11 @@ services:
156156
tags:
157157
- { name: ibexa.admin_ui.config.provider, key: 'damWidget' }
158158

159+
Ibexa\Bundle\AdminUi\Asset\RtlEntrypointLookup:
160+
decorates: 'webpack_encore.entrypoint_lookup[ibexa]'
161+
arguments:
162+
$inner: '@.inner'
163+
159164
# Resolvers
160165
Ibexa\AdminUi\REST\Generator\ApplicationConfigRestGeneratorRegistry:
161166
arguments:

src/bundle/Resources/views/themes/admin/account/base.html.twig

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
{# !! TEST PURPOSE - REMOVE BEFORE MERGE !! #}
22
<!DOCTYPE html>
3-
<html {{ ibexa_rtl ? 'dir="rtl"' : '' }}>
3+
<html {{ ibexa_is_rtl ? 'dir="rtl"' : '' }}>
44
<head>
55
<meta charset="UTF-8" />
66
<title>Ibexa DXP</title>
7-
8-
{{ ibexa_encore_entry_link_tags('ibexa-admin-ui-security-base-css', null, 'ibexa') }}
9-
7+
{{ encore_entry_link_tags('ibexa-admin-ui-security-base-css', null, 'ibexa') }}
108
<link rel="icon" type="image/x-icon" href="{{ asset('bundles/ibexaadminui/img/favicon.ico') }}" />
119

1210
<script src="{{ asset('bundles/ibexaadminuiassets/vendors/@popperjs/core/dist/umd/popper.min.js') }}"></script>

src/bundle/Resources/views/themes/admin/ui/layout.html.twig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,10 @@
9494
<script type="text/javascript" src="//cdn.crowdin.com/jipt/jipt.js"></script>
9595
{% endif %}
9696
<title>{% block title %}Ibexa DXP{% endblock %}</title>
97-
98-
{{ ibexa_encore_entry_link_tags('ibexa-admin-ui-layout-css', null, 'ibexa', ['ibexa-admin-ui-overwrite-rtl-css']) }}
99-
97+
{{ encore_entry_link_tags('ibexa-admin-ui-layout-css', null, 'ibexa') }}
98+
{% if ibexa_is_rtl %}
99+
{{ encore_entry_link_tags('ibexa-admin-ui-overwrite-rtl-css', null, 'ibexa') }}
100+
{% endif %}
100101
{% block stylesheets %}{% endblock %}
101102
<link rel="icon" type="image/x-icon" href="{{ asset('bundles/ibexaadminui/img/favicon.ico') }}" />
102103
<link rel="icon" type="image/png" sizes="16x16" href="{{ asset('bundles/ibexaadminui/img/favicon-16x16.png') }}" />
@@ -123,7 +124,6 @@
123124
<div id="react-udw" data-filter-subtree-udw-config="{{ ibexa_udw_config('single_container', {}) }}"></div>
124125

125126
{% block header_row %}
126-
127127
<header class="ibexa-main-header">
128128
<div class="ibexa-main-header__brand-column">
129129
{% block brand %}
Lines changed: 13 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,28 @@
11
<?php
2+
3+
/**
4+
* @copyright Copyright (C) Ibexa AS. All rights reserved.
5+
* @license For full copyright and license information view LICENSE file distributed with this source code.
6+
*/
7+
declare(strict_types=1);
8+
29
namespace Ibexa\Bundle\AdminUi\Templating\Twig;
310

4-
use Ibexa\User\UserSetting\UserSettingService;
5-
use Symfony\Component\Asset\Packages;
6-
use Symfony\Component\HttpFoundation\RequestStack;
11+
use Ibexa\Contracts\AdminUi\Rtl\RtlModeResolverInterface;
712
use Twig\Extension\AbstractExtension;
813
use Twig\Extension\GlobalsInterface;
9-
use Twig\TwigFunction;
1014

11-
class RtlExtension extends AbstractExtension implements GlobalsInterface
15+
final class RtlExtension extends AbstractExtension implements GlobalsInterface
1216
{
13-
private Packages $assets;
14-
private RequestStack $requestStack;
15-
private UserSettingService $userSettingService;
16-
private array $rtlLanguages;
17-
18-
public function __construct(Packages $assets, RequestStack $requestStack, UserSettingService $userSettingService, array $rtlLanguages = [])
19-
{
20-
$this->assets = $assets;
21-
$this->requestStack = $requestStack;
22-
$this->userSettingService = $userSettingService;
23-
$this->rtlLanguages = $rtlLanguages;
17+
public function __construct(
18+
private readonly RtlModeResolverInterface $rtlModeResolver,
19+
) {
2420
}
2521

2622
public function getGlobals(): array
2723
{
2824
return [
29-
'ibexa_is_rtl' => $this->requestStack->getCurrentRequest() !== null && $this->isRtl(),
30-
];
31-
}
32-
33-
public function isRtl(): bool
34-
{
35-
$userLanguage = $this->userSettingService->getUserSetting('language')->value;
36-
37-
return in_array($userLanguage, $this->rtlLanguages, true);
38-
}
39-
40-
public function getFunctions()
41-
{
42-
return [
43-
new TwigFunction('ibexa_encore_entry_link_tags', [$this, 'renderRtlEncoreEntryLinkTags'], ['is_safe' => ['html']]),
25+
'ibexa_is_rtl' => $this->rtlModeResolver->isRtl(),
4426
];
4527
}
46-
47-
public function renderRtlEncoreEntryLinkTags(string $entryName, ?string $packageName = null, ?string $entrypointName = null, array $extraRtlEntries = [])
48-
{
49-
$fileSuffix = $this->isRtl() ? '-rtl.css' : '.css';
50-
$url = $this->assets->getUrl("assets/ibexa/build/{$entryName}{$fileSuffix}", $packageName);
51-
$tags = sprintf('<link rel="stylesheet" href="%s" />', htmlspecialchars($url, ENT_QUOTES));
52-
53-
if ($this->isRtl()) {
54-
foreach ($extraRtlEntries as $extra) {
55-
$extraEntry = is_array($extra) ? $extra['entry'] : $extra;
56-
$extraPackage = is_array($extra) ? ($extra['package'] ?? null) : null;
57-
$extraUrl = $this->assets->getUrl("assets/ibexa/build/{$extraEntry}.css", $extraPackage);
58-
$tags .= "\n" . sprintf('<link rel="stylesheet" href="%s" />', htmlspecialchars($extraUrl, ENT_QUOTES));
59-
}
60-
}
61-
62-
return $tags;
63-
}
6428
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (C) Ibexa AS. All rights reserved.
5+
* @license For full copyright and license information view LICENSE file distributed with this source code.
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace Ibexa\Contracts\AdminUi\Rtl;
10+
11+
interface RtlModeResolverInterface
12+
{
13+
public function isRtl(): bool;
14+
}

0 commit comments

Comments
 (0)