Skip to content

Commit b942418

Browse files
OstafinLciastektk
andauthored
IBX-6315: Edit embedded items (#872)
Co-authored-by: Tomasz Kryszan <[email protected]>
1 parent 69e8a2c commit b942418

36 files changed

+1490
-174
lines changed

phpstan-baseline-7.4.neon

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,6 @@ parameters:
210210
count: 1
211211
path: src/lib/Pagination/Mapper/AbstractPagerContentToDataMapper.php
212212

213-
-
214-
message: "#^Parameter \\#1 \\$input of function array_filter expects array, iterable\\<Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Language\\> given\\.$#"
215-
count: 1
216-
path: src/lib/Permission/PermissionChecker.php
217-
218213
-
219214
message: "#^Parameter \\#1 \\$var of function count expects array\\|Countable, iterable\\<Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\User\\\\UserGroup\\> given\\.$#"
220215
count: 1

phpstan-baseline-8.0.neon

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,6 @@ parameters:
150150
count: 1
151151
path: src/lib/Pagination/Mapper/AbstractPagerContentToDataMapper.php
152152

153-
-
154-
message: "#^Parameter \\#1 \\$array of function array_filter expects array, iterable\\<Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Language\\> given\\.$#"
155-
count: 1
156-
path: src/lib/Permission/PermissionChecker.php
157-
158153
-
159154
message: "#^Parameter \\#1 \\$value of function count expects array\\|Countable, iterable\\<Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\User\\\\UserGroup\\> given\\.$#"
160155
count: 1

phpstan-baseline.neon

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8445,6 +8445,11 @@ parameters:
84458445
count: 1
84468446
path: src/lib/Pagination/Pagerfanta/URLWildcardAdapter.php
84478447

8448+
-
8449+
message: "#^Access to protected property Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\User\\\\LookupLimitationResult\\:\\:\\$hasAccess\\.$#"
8450+
count: 1
8451+
path: src/lib/Permission/LimitationResolver.php
8452+
84488453
-
84498454
message: "#^Access to protected property Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\User\\\\LookupLimitationResult\\:\\:\\$lookupPolicyLimitations\\.$#"
84508455
count: 2
@@ -8500,11 +8505,6 @@ parameters:
85008505
count: 1
85018506
path: src/lib/Permission/PermissionChecker.php
85028507

8503-
-
8504-
message: "#^Parameter \\#1 \\$contentTypeIds of method Ibexa\\\\Contracts\\\\Core\\\\Limitation\\\\Target\\\\Builder\\\\VersionBuilder\\:\\:createFromAnyContentTypeOf\\(\\) expects array\\<int\\>, array\\<string\\> given\\.$#"
8505-
count: 2
8506-
path: src/lib/Permission/PermissionChecker.php
8507-
85088508
-
85098509
message: "#^Method Ibexa\\\\AdminUi\\\\QueryType\\\\LocationPathQueryType\\:\\:doGetQuery\\(\\) has parameter \\$parameters with no value type specified in iterable type array\\.$#"
85108510
count: 1
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
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\Controller\Permission;
10+
11+
use Ibexa\AdminUi\Permission\LimitationResolverInterface;
12+
use Ibexa\Contracts\AdminUi\Controller\Controller;
13+
use Ibexa\Contracts\Core\Repository\ContentService;
14+
use Ibexa\Contracts\Core\Repository\LocationService;
15+
use Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo;
16+
use Ibexa\Contracts\Core\Repository\Values\Content\Location;
17+
use Ibexa\Contracts\Core\Repository\Values\Content\VersionInfo;
18+
use Symfony\Component\HttpFoundation\JsonResponse;
19+
use Symfony\Component\HttpFoundation\Response;
20+
21+
final class LanguageLimitationController extends Controller
22+
{
23+
private ContentService $contentService;
24+
25+
private LimitationResolverInterface $limitationResolver;
26+
27+
private LocationService $locationService;
28+
29+
public function __construct(
30+
ContentService $contentService,
31+
LimitationResolverInterface $limitationResolver,
32+
LocationService $locationService
33+
) {
34+
$this->contentService = $contentService;
35+
$this->limitationResolver = $limitationResolver;
36+
$this->locationService = $locationService;
37+
}
38+
39+
public function loadLanguageLimitationsForContentCreateAction(Location $location): Response
40+
{
41+
$contentInfo = $location->getContentInfo();
42+
$contentType = $contentInfo->getContentType();
43+
$contentCreateStruct = $this->contentService->newContentCreateStruct(
44+
$contentType,
45+
$contentInfo->getMainLanguageCode()
46+
);
47+
$contentCreateStruct->sectionId = $contentInfo->getSection();
48+
$locationCreateStruct = $this->locationService->newLocationCreateStruct($location->id);
49+
50+
return new JsonResponse(
51+
$this->limitationResolver->getLanguageLimitations(
52+
'create',
53+
$contentCreateStruct,
54+
[],
55+
[
56+
$locationCreateStruct,
57+
]
58+
)
59+
);
60+
}
61+
62+
public function loadLanguageLimitationsForContentEditAction(
63+
ContentInfo $contentInfo,
64+
?VersionInfo $versionInfo = null,
65+
?Location $location = null
66+
): Response {
67+
return new JsonResponse(
68+
$this->getLanguageLimitationsByFunction(
69+
'edit',
70+
$contentInfo,
71+
$versionInfo,
72+
$location
73+
)
74+
);
75+
}
76+
77+
public function loadLanguageLimitationsForContentReadAction(
78+
ContentInfo $contentInfo,
79+
?VersionInfo $versionInfo = null,
80+
?Location $location = null
81+
): Response {
82+
return new JsonResponse(
83+
$this->getLanguageLimitationsByFunction(
84+
'read',
85+
$contentInfo,
86+
$versionInfo,
87+
$location
88+
)
89+
);
90+
}
91+
92+
/**
93+
* @return array<array{
94+
* languageCode: string,
95+
* name: string,
96+
* hasAccess: bool,
97+
* }>
98+
*/
99+
private function getLanguageLimitationsByFunction(
100+
string $function,
101+
ContentInfo $contentInfo,
102+
?VersionInfo $versionInfo = null,
103+
?Location $location = null
104+
): array {
105+
$versionInfo ??= $this->contentService->loadVersionInfo($contentInfo);
106+
$location ??= $contentInfo->getMainLocation();
107+
$targets = [];
108+
109+
if (null !== $location) {
110+
$targets[] = $location;
111+
}
112+
113+
return $this->limitationResolver->getLanguageLimitations(
114+
$function,
115+
$contentInfo,
116+
$versionInfo->getLanguages(),
117+
$targets
118+
);
119+
}
120+
}

src/bundle/Resources/config/routing.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -958,3 +958,33 @@ ibexa.asset.upload_image:
958958
defaults:
959959
_controller: 'Ibexa\Bundle\AdminUi\Controller\AssetController::uploadImageAction'
960960
methods: [POST]
961+
962+
#
963+
# Permissions
964+
#
965+
ibexa.permission.limitation.language.content_create:
966+
path: /permission/limitation/language/content-create/{locationId}
967+
options:
968+
expose: true
969+
controller: 'Ibexa\Bundle\AdminUi\Controller\Permission\LanguageLimitationController::loadLanguageLimitationsForContentCreateAction'
970+
methods: [GET]
971+
requirements:
972+
locationId: \d+
973+
974+
ibexa.permission.limitation.language.content_edit:
975+
path: /permission/limitation/language/content-edit/{contentInfoId}
976+
options:
977+
expose: true
978+
controller: 'Ibexa\Bundle\AdminUi\Controller\Permission\LanguageLimitationController::loadLanguageLimitationsForContentEditAction'
979+
methods: [GET]
980+
requirements:
981+
contentInfoId: \d+
982+
983+
ibexa.permission.limitation.language.content_read:
984+
path: /permission/limitation/language/content-read/{contentInfoId}
985+
options:
986+
expose: true
987+
controller: 'Ibexa\Bundle\AdminUi\Controller\Permission\LanguageLimitationController::loadLanguageLimitationsForContentReadAction'
988+
methods: [GET]
989+
requirements:
990+
contentInfoId: \d+

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,10 @@ services:
3939
public: false
4040

4141
Ibexa\Contracts\AdminUi\Component\Renderer\RendererInterface: '@Ibexa\AdminUi\Component\Renderer\DefaultRenderer'
42+
43+
ibexa.adminui.layout.content.after:
44+
parent: Ibexa\AdminUi\Component\TwigComponent
45+
arguments:
46+
$template: '@@ibexadesign/ui/layout_content_after.html.twig'
47+
tags:
48+
- { name: ibexa.admin_ui.component, group: 'layout-content-after' }

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,9 @@ services:
212212
autowire: true
213213

214214
Ibexa\Bundle\AdminUi\Controller\User\InvitationController: ~
215+
216+
Ibexa\Bundle\AdminUi\Controller\Permission\LanguageLimitationController:
217+
parent: Ibexa\Contracts\AdminUi\Controller\Controller
218+
autowire: true
219+
tags:
220+
- controller.service_arguments

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,8 @@ services:
1010
alias: Ibexa\AdminUi\Permission\PermissionChecker
1111

1212
Ibexa\AdminUi\Permission\LookupLimitationsTransformer: ~
13+
14+
Ibexa\AdminUi\Permission\LimitationResolver: ~
15+
16+
Ibexa\AdminUi\Permission\LimitationResolverInterface:
17+
alias: Ibexa\AdminUi\Permission\LimitationResolver

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ services:
9696

9797
Ibexa\Bundle\AdminUi\Templating\Twig\ContentTypeIconExtension: ~
9898

99+
Ibexa\Bundle\AdminUi\Templating\Twig\EmbeddedItemEditFormExtension: ~
100+
99101
Ibexa\AdminUi\UI\Config\Provider\UserContentTypes:
100102
tags:
101103
- { name: ibexa.admin_ui.config.provider, key: 'userContentTypes' }

src/bundle/Resources/encore/ibexa.js.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ const layout = [
6464
path.resolve(__dirname, '../public/js/scripts/admin.back.to.top.js'),
6565
path.resolve(__dirname, '../public/js/scripts/admin.middle.ellipsis.js'),
6666
path.resolve(__dirname, '../public/js/scripts/admin.form.error.js'),
67+
path.resolve(__dirname, '../public/js/scripts/embedded.item.actions'),
6768
path.resolve(__dirname, '../public/js/scripts/widgets/flatpickr.js'),
6869
];
6970
const fieldTypes = [];

0 commit comments

Comments
 (0)