Skip to content

Commit 9111920

Browse files
authored
[Object Bricks][Config]: Endpoints part 3 (#1676)
* add endpoints for object bricks and custom layouts * Apply php-cs-fixer changes
1 parent 6071dad commit 9111920

49 files changed

Lines changed: 1576 additions & 153 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

config/class.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ services:
5353
Pimcore\Bundle\StudioBackendBundle\Class\Service\LayoutServiceInterface:
5454
class: Pimcore\Bundle\StudioBackendBundle\Class\Service\LayoutService
5555

56+
Pimcore\Bundle\StudioBackendBundle\Class\Service\FieldsByTypeServiceInterface:
57+
class: Pimcore\Bundle\StudioBackendBundle\Class\Service\FieldsByTypeService
58+
5659
#
5760
# Repositories
5861
#
@@ -108,6 +111,9 @@ services:
108111
Pimcore\Bundle\StudioBackendBundle\Class\Hydrator\ObjectBrick\ObjectBrickConfigHydratorInterface:
109112
class: Pimcore\Bundle\StudioBackendBundle\Class\Hydrator\ObjectBrick\ObjectBrickConfigHydrator
110113

114+
Pimcore\Bundle\StudioBackendBundle\Class\Hydrator\FieldByTypeHydratorInterface:
115+
class: Pimcore\Bundle\StudioBackendBundle\Class\Hydrator\FieldByTypeHydrator
116+
111117
Pimcore\Bundle\StudioBackendBundle\Class\Hydrator\CompactLayoutHydratorInterface:
112118
class: Pimcore\Bundle\StudioBackendBundle\Class\Hydrator\CompactLayoutHydrator
113119

doc/05_Additional_Custom_Attributes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ final class AssetEvent extends AbstractPreResponseEvent
8888
- `pre_response.class_definition.identifier_data`
8989
- `pre_response.class_definition.object_brick_data`
9090
- `pre_response.class_definition.tree`
91+
- `pre_response.class_field_by_type`
9192
- `pre_response.classification_store.collection`
9293
- `pre_response.classification_store.config_collection`
9394
- `pre_response.classification_store.group`

src/Class/Attribute/Request/CustomLayoutUpdateRequestBody.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
#[Attribute(Attribute::TARGET_METHOD)]
2222
final class CustomLayoutUpdateRequestBody extends RequestBody
2323
{
24-
public function __construct()
24+
public function __construct(bool $required = true)
2525
{
2626
parent::__construct(
27-
required: true,
27+
required: $required,
2828
content: new JsonContent(
2929
ref: CustomLayoutUpdate::class,
3030
type: 'object'

src/Class/Controller/CollectionController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public function listClasses(): JsonResponse
6868
new PermissionsToCheck([
6969
UserPermissions::CLASS_DEFINITION->value,
7070
UserPermissions::DATA_OBJECTS->value,
71+
UserPermissions::OBJECT_BRICKS->value,
7172
UserPermissions::USER_MANAGEMENT->value,
7273
])
7374
);

src/Class/Controller/CustomLayout/ClassCollectionController.php

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
namespace Pimcore\Bundle\StudioBackendBundle\Class\Controller\CustomLayout;
1515

1616
use OpenApi\Attributes\Get;
17+
use Pimcore\Bundle\StudioBackendBundle\Class\MappedParameter\ClassIdsParameters;
1718
use Pimcore\Bundle\StudioBackendBundle\Class\Schema\CustomLayout\CustomLayoutCompact;
1819
use Pimcore\Bundle\StudioBackendBundle\Class\Service\CustomLayoutServiceInterface;
1920
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
20-
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Path\StringParameter;
21+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Query\ClassIdsParameter;
2122
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Property\GenericCollection;
2223
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\Content\CollectionJson;
2324
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\DefaultResponses;
@@ -27,15 +28,21 @@
2728
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\UserPermissions;
2829
use Pimcore\Bundle\StudioBackendBundle\Util\Trait\PaginatedResponseTrait;
2930
use Symfony\Component\HttpFoundation\JsonResponse;
31+
use Symfony\Component\HttpKernel\Attribute\MapQueryString;
3032
use Symfony\Component\Routing\Attribute\Route;
3133
use Symfony\Component\Security\Http\Attribute\IsGranted;
3234
use Symfony\Component\Serializer\SerializerInterface;
3335
use function count;
3436

37+
/**
38+
* @internal
39+
*/
3540
final class ClassCollectionController extends AbstractApiController
3641
{
3742
use PaginatedResponseTrait;
3843

44+
private const string ROUTE = '/class/custom-layout/collection';
45+
3946
public function __construct(
4047
SerializerInterface $serializer,
4148
private readonly CustomLayoutServiceInterface $customLayoutService
@@ -44,34 +51,32 @@ public function __construct(
4451
}
4552

4653
#[Route(
47-
'/class/custom-layout/collection/{dataObjectClass}',
54+
self::ROUTE,
4855
name: 'pimcore_studio_api_class_custom_layout_collection',
49-
methods: ['GET']
56+
methods: ['GET'],
5057
)]
5158
#[IsGranted(UserPermissions::DATA_OBJECTS->value)]
5259
#[Get(
53-
path: self::PREFIX . '/class/custom-layout/collection/{dataObjectClass}',
60+
path: self::PREFIX . self::ROUTE,
5461
operationId: 'class_custom_layout_collection',
5562
description: 'class_custom_layout_collection_description',
5663
summary: 'class_custom_layout_collection_summary',
5764
tags: [Tags::ClassDefinition->value],
5865
)]
59-
#[StringParameter(
60-
name: 'dataObjectClass',
61-
example: 'CAR',
62-
description: 'class_custom_layout_collection_data_object_class',
63-
required: true
64-
)]
66+
#[ClassIdsParameter]
6567
#[SuccessResponse(
6668
description: 'class_custom_layout_collection_success_response',
6769
content: new CollectionJson(new GenericCollection(CustomLayoutCompact::class))
6870
)]
6971
#[DefaultResponses([
7072
HttpResponseCodes::UNAUTHORIZED,
7173
])]
72-
public function getCustomLayoutsByClass(string $dataObjectClass): JsonResponse
73-
{
74-
$items = $this->customLayoutService->getCustomLayoutCollection($dataObjectClass);
74+
public function getCustomLayoutsByClass(
75+
#[MapQueryString] ClassIdsParameters $parameters = new ClassIdsParameters()
76+
): JsonResponse {
77+
$items = $this->customLayoutService->getCustomLayoutCollection(
78+
$parameters->getClassIdsArray()
79+
);
7580

7681
return $this->getPaginatedCollection(
7782
$this->serializer,

src/Class/Controller/DefinitionConfiguration/ExportController.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Pimcore\Bundle\StudioBackendBundle\Class\Service\ClassDefinitionServiceInterface;
1818
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
1919
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException;
20+
use Pimcore\Bundle\StudioBackendBundle\Export\Service\DownloadServiceInterface;
2021
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Path\StringParameter;
2122
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\Content\MediaType;
2223
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\DefaultResponses;
@@ -38,6 +39,7 @@ final class ExportController extends AbstractApiController
3839
public function __construct(
3940
SerializerInterface $serializer,
4041
private readonly ClassDefinitionServiceInterface $classDefinitionService,
42+
private readonly DownloadServiceInterface $downloadService,
4143
) {
4244
parent::__construct($serializer);
4345
}
@@ -75,6 +77,11 @@ public function __construct(
7577
])]
7678
public function exportClassDefinitionById(string $id): Response
7779
{
78-
return $this->classDefinitionService->exportClassDefinition($id);
80+
$export = $this->classDefinitionService->exportClassDefinition($id);
81+
82+
return $this->downloadService->downloadJSON(
83+
$export->getJson(),
84+
$export->getFileName()
85+
);
7986
}
8087
}

src/Class/Controller/FieldCollection/ExportController.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Pimcore\Bundle\StudioBackendBundle\Class\Service\FieldCollection\FieldCollectionServiceInterface;
1818
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
1919
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException;
20+
use Pimcore\Bundle\StudioBackendBundle\Export\Service\DownloadServiceInterface;
2021
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Path\StringParameter;
2122
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\Content\MediaType;
2223
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\DefaultResponses;
@@ -41,6 +42,7 @@ final class ExportController extends AbstractApiController
4142
public function __construct(
4243
SerializerInterface $serializer,
4344
private readonly FieldCollectionServiceInterface $fieldCollectionService,
45+
private readonly DownloadServiceInterface $downloadService,
4446
) {
4547
parent::__construct($serializer);
4648
}
@@ -78,6 +80,11 @@ public function __construct(
7880
])]
7981
public function exportFieldCollection(string $key): Response
8082
{
81-
return $this->fieldCollectionService->exportFieldCollection($key);
83+
$export = $this->fieldCollectionService->exportFieldCollection($key);
84+
85+
return $this->downloadService->downloadJSON(
86+
$export->getJson(),
87+
$export->getFileName()
88+
);
8289
}
8390
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
/**
5+
* This source file is available under the terms of the
6+
* Pimcore Open Core License (POCL)
7+
* Full copyright and license information is available in
8+
* LICENSE.md which is distributed with this source code.
9+
*
10+
* @copyright Copyright (c) Pimcore GmbH (https://www.pimcore.com)
11+
* @license Pimcore Open Core License (POCL)
12+
*/
13+
14+
namespace Pimcore\Bundle\StudioBackendBundle\Class\Controller;
15+
16+
use OpenApi\Attributes\Get;
17+
use Pimcore\Bundle\StudioBackendBundle\Class\MappedParameter\FieldsByTypeParameters;
18+
use Pimcore\Bundle\StudioBackendBundle\Class\Schema\FieldByType;
19+
use Pimcore\Bundle\StudioBackendBundle\Class\Service\FieldsByTypeServiceInterface;
20+
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
21+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Query\StringParameter;
22+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Property\GenericCollection;
23+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\Content\CollectionJson;
24+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\DefaultResponses;
25+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\SuccessResponse;
26+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags;
27+
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\HttpResponseCodes;
28+
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\UserPermissions;
29+
use Pimcore\Bundle\StudioBackendBundle\Util\Trait\PaginatedResponseTrait;
30+
use Symfony\Component\HttpFoundation\JsonResponse;
31+
use Symfony\Component\HttpKernel\Attribute\MapQueryString;
32+
use Symfony\Component\Routing\Attribute\Route;
33+
use Symfony\Component\Security\Http\Attribute\IsGranted;
34+
use Symfony\Component\Serializer\SerializerInterface;
35+
use function count;
36+
37+
/**
38+
* @internal
39+
*/
40+
final class FieldsByTypeController extends AbstractApiController
41+
{
42+
use PaginatedResponseTrait;
43+
44+
private const string ROUTE = '/class/definition/fields-by-type';
45+
46+
public function __construct(
47+
SerializerInterface $serializer,
48+
private readonly FieldsByTypeServiceInterface $fieldsByTypeService,
49+
) {
50+
parent::__construct($serializer);
51+
}
52+
53+
#[Route(
54+
self::ROUTE,
55+
name: 'pimcore_studio_api_class_fields_by_type',
56+
methods: ['GET']
57+
)]
58+
#[IsGranted(UserPermissions::CLASS_DEFINITION->value)]
59+
#[Get(
60+
path: self::PREFIX . self::ROUTE,
61+
operationId: 'class_get_fields_by_type',
62+
description: 'class_get_fields_by_type_description',
63+
summary: 'class_get_fields_by_type_summary',
64+
tags: [Tags::ClassDefinition->value],
65+
)]
66+
#[StringParameter(
67+
name: 'classId',
68+
example: 'EV',
69+
description: 'The class ID to retrieve fields for.',
70+
required: true
71+
)]
72+
#[StringParameter(
73+
name: 'type',
74+
example: 'manyToOneRelation,objectbricks',
75+
description: 'Comma-separated list of field types to filter by.',
76+
required: true
77+
)]
78+
#[SuccessResponse(
79+
description: 'class_get_fields_by_type_success_response',
80+
content: new CollectionJson(new GenericCollection(FieldByType::class))
81+
)]
82+
#[DefaultResponses([
83+
HttpResponseCodes::UNAUTHORIZED,
84+
HttpResponseCodes::NOT_FOUND,
85+
])]
86+
public function getFieldsByType(
87+
#[MapQueryString] FieldsByTypeParameters $parameters
88+
): JsonResponse {
89+
$fields = $this->fieldsByTypeService->getFieldsByType($parameters);
90+
91+
return $this->getPaginatedCollection($this->serializer, $fields, count($fields));
92+
}
93+
}

src/Class/Controller/Folder/CollectionController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
use OpenApi\Attributes\Get;
1717
use Pimcore\Bundle\StudioBackendBundle\Class\Schema\Folder\ClassDefinitionFolderItem;
18-
use Pimcore\Bundle\StudioBackendBundle\Class\Service\ClassDefinitionServiceInterface;
18+
use Pimcore\Bundle\StudioBackendBundle\Class\Service\ClassDefinitionTreeServiceInterface;
1919
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
2020
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException;
2121
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Path\IdParameter;
@@ -43,7 +43,7 @@ final class CollectionController extends AbstractApiController
4343

4444
public function __construct(
4545
SerializerInterface $serializer,
46-
private readonly ClassDefinitionServiceInterface $classDefinitionService,
46+
private readonly ClassDefinitionTreeServiceInterface $classDefinitionTreeService,
4747

4848
) {
4949
parent::__construct($serializer);
@@ -78,7 +78,7 @@ public function __construct(
7878
public function getFolderClassList(
7979
int $folderId
8080
): JsonResponse {
81-
$collection = $this->classDefinitionService->getClassDefinitionIdsInsideFolder($folderId);
81+
$collection = $this->classDefinitionTreeService->getClassDefinitionIdsInsideFolder($folderId);
8282

8383
return $this->getPaginatedCollection(
8484
$this->serializer,
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
/**
5+
* This source file is available under the terms of the
6+
* Pimcore Open Core License (POCL)
7+
* Full copyright and license information is available in
8+
* LICENSE.md which is distributed with this source code.
9+
*
10+
* @copyright Copyright (c) Pimcore GmbH (https://www.pimcore.com)
11+
* @license Pimcore Open Core License (POCL)
12+
*/
13+
14+
namespace Pimcore\Bundle\StudioBackendBundle\Class\Controller\ObjectBrick;
15+
16+
use OpenApi\Attributes\Get;
17+
use Pimcore\Bundle\StudioBackendBundle\Class\Schema\ClassDefinitionList;
18+
use Pimcore\Bundle\StudioBackendBundle\Class\Service\ClassDefinitionServiceInterface;
19+
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
20+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Property\GenericCollection;
21+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\Content\CollectionJson;
22+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\DefaultResponses;
23+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\SuccessResponse;
24+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags;
25+
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\HttpResponseCodes;
26+
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\UserPermissions;
27+
use Pimcore\Bundle\StudioBackendBundle\Util\Trait\PaginatedResponseTrait;
28+
use Symfony\Component\HttpFoundation\JsonResponse;
29+
use Symfony\Component\Routing\Attribute\Route;
30+
use Symfony\Component\Security\Http\Attribute\IsGranted;
31+
use Symfony\Component\Serializer\SerializerInterface;
32+
use function count;
33+
34+
/**
35+
* @internal
36+
*/
37+
final class ClassesController extends AbstractApiController
38+
{
39+
use PaginatedResponseTrait;
40+
41+
private const string ROUTE = '/class/object-brick/classes';
42+
43+
public function __construct(
44+
SerializerInterface $serializer,
45+
private readonly ClassDefinitionServiceInterface $classDefinitionService,
46+
) {
47+
parent::__construct($serializer);
48+
}
49+
50+
#[Route(
51+
self::ROUTE,
52+
name: 'pimcore_studio_api_class_object_brick_classes',
53+
methods: ['GET'],
54+
priority: 10
55+
)]
56+
#[IsGranted(UserPermissions::OBJECT_BRICKS->value)]
57+
#[Get(
58+
path: self::PREFIX . self::ROUTE,
59+
operationId: 'class_object_brick_classes',
60+
description: 'class_object_brick_classes_description',
61+
summary: 'class_object_brick_classes_summary',
62+
tags: [Tags::ClassDefinition->value],
63+
)]
64+
#[SuccessResponse(
65+
description: 'class_object_brick_classes_success_response',
66+
content: new CollectionJson(new GenericCollection(ClassDefinitionList::class))
67+
)]
68+
#[DefaultResponses([
69+
HttpResponseCodes::UNAUTHORIZED,
70+
])]
71+
public function getClassesWithObjectBricks(): JsonResponse
72+
{
73+
$items = $this->classDefinitionService->getClassDefinitionsWithObjectBricks();
74+
75+
return $this->getPaginatedCollection(
76+
$this->serializer,
77+
$items,
78+
count($items)
79+
);
80+
}
81+
}

0 commit comments

Comments
 (0)