Skip to content

Commit 7e6e561

Browse files
authored
[Select options] Add config endpoints (#1679)
* add endpoints for select options * Apply php-cs-fixer changes * fix sonar * Apply php-cs-fixer changes
1 parent 4f94297 commit 7e6e561

27 files changed

Lines changed: 1482 additions & 19 deletions

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"php": "~8.3.0 || ~8.4.0",
2121
"league/csv": "^9.22",
2222
"nesbot/carbon": "^3.8.4",
23-
"pimcore/static-resolver-bundle": "^3.4.0 || ^2026.1",
23+
"pimcore/static-resolver-bundle": "^3.5.0 || ^2026.1",
2424
"pimcore/generic-data-index-bundle": "^2.4.0 || ^2026.1",
2525
"pimcore/pimcore": "^12.3 || ^2026.1",
2626
"zircote/swagger-php": "^4.8 || ^5.0",

config/class.yaml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,11 @@ services:
4141
Pimcore\Bundle\StudioBackendBundle\Class\Service\IdentifierServiceInterface:
4242
class: Pimcore\Bundle\StudioBackendBundle\Class\Service\IdentifierService
4343

44-
Pimcore\Bundle\StudioBackendBundle\Class\Service\SelectOptionServiceInterface:
45-
class: Pimcore\Bundle\StudioBackendBundle\Class\Service\SelectOptionService
44+
Pimcore\Bundle\StudioBackendBundle\Class\Service\SelectOptions\TreeServiceInterface:
45+
class: Pimcore\Bundle\StudioBackendBundle\Class\Service\SelectOptions\TreeService
46+
47+
Pimcore\Bundle\StudioBackendBundle\Class\Service\SelectOptions\SelectOptionServiceInterface:
48+
class: Pimcore\Bundle\StudioBackendBundle\Class\Service\SelectOptions\SelectOptionService
4649

4750
Pimcore\Bundle\StudioBackendBundle\Class\Service\ClassDefinitionTreeServiceInterface:
4851
class: Pimcore\Bundle\StudioBackendBundle\Class\Service\ClassDefinitionTreeService
@@ -72,6 +75,9 @@ services:
7275
Pimcore\Bundle\StudioBackendBundle\Class\Repository\CustomLayoutRepositoryInterface:
7376
class: Pimcore\Bundle\StudioBackendBundle\Class\Repository\CustomLayoutRepository
7477

78+
Pimcore\Bundle\StudioBackendBundle\Class\Repository\SelectOptionRepositoryInterface:
79+
class: Pimcore\Bundle\StudioBackendBundle\Class\Repository\SelectOptionRepository
80+
7581
#
7682
# Hydrators
7783
#
@@ -146,3 +152,6 @@ services:
146152

147153
Pimcore\Bundle\StudioBackendBundle\Class\Hydrator\SelectOption\TreeFolderHydratorInterface:
148154
class: Pimcore\Bundle\StudioBackendBundle\Class\Hydrator\SelectOption\TreeFolderHydrator
155+
156+
Pimcore\Bundle\StudioBackendBundle\Class\Hydrator\SelectOption\DetailHydratorInterface:
157+
class: Pimcore\Bundle\StudioBackendBundle\Class\Hydrator\SelectOption\DetailHydrator

doc/05_Additional_Custom_Attributes.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ final class AssetEvent extends AbstractPreResponseEvent
160160
- `pre_response.recycle_bin.item`
161161
- `pre_response.role_tree_node`
162162
- `pre_response.schedule`
163+
- `pre_response.select_option.detail`
163164
- `pre_response.select_option.tree`
165+
- `pre_response.select_option.usage_item`
164166
- `pre_response.settings.active_bundle`
165167
- `pre_response.settings.available_country`
166168
- `pre_response.simple_search.preview`
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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\SelectOptions;
15+
16+
use OpenApi\Attributes\JsonContent;
17+
use OpenApi\Attributes\Post;
18+
use Pimcore\Bundle\StudioBackendBundle\Class\MappedParameter\CreateSelectOptionParameters;
19+
use Pimcore\Bundle\StudioBackendBundle\Class\Schema\SelectOption\CreateSelectOption;
20+
use Pimcore\Bundle\StudioBackendBundle\Class\Schema\SelectOption\SelectOptionDetail;
21+
use Pimcore\Bundle\StudioBackendBundle\Class\Service\SelectOptions\SelectOptionServiceInterface;
22+
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
23+
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\ElementExistsException;
24+
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\ElementSavingFailedException;
25+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Request\ReferenceRequestBody;
26+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\DefaultResponses;
27+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\SuccessResponse;
28+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags;
29+
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\HttpResponseCodes;
30+
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\UserPermissions;
31+
use Symfony\Component\HttpFoundation\JsonResponse;
32+
use Symfony\Component\HttpKernel\Attribute\MapRequestPayload;
33+
use Symfony\Component\Routing\Attribute\Route;
34+
use Symfony\Component\Security\Http\Attribute\IsGranted;
35+
use Symfony\Component\Serializer\SerializerInterface;
36+
37+
/**
38+
* @internal
39+
*/
40+
final class CreateController extends AbstractApiController
41+
{
42+
private const string ROUTE = '/class/select-option';
43+
44+
public function __construct(
45+
SerializerInterface $serializer,
46+
private readonly SelectOptionServiceInterface $selectOptionService,
47+
) {
48+
parent::__construct($serializer);
49+
}
50+
51+
/**
52+
* @throws ElementExistsException|ElementSavingFailedException
53+
*/
54+
#[Route(self::ROUTE, name: 'pimcore_studio_api_class_select_option_create', methods: ['POST'])]
55+
#[IsGranted(UserPermissions::SELECT_OPTIONS->value)]
56+
#[Post(
57+
path: self::PREFIX . self::ROUTE,
58+
operationId: 'class_select_option_create',
59+
description: 'class_select_option_create_description',
60+
summary: 'class_select_option_create_summary',
61+
tags: [Tags::ClassDefinition->value],
62+
)]
63+
#[ReferenceRequestBody(CreateSelectOption::class)]
64+
#[SuccessResponse(
65+
description: 'class_select_option_create_success_response',
66+
content: new JsonContent(ref: SelectOptionDetail::class)
67+
)]
68+
#[DefaultResponses([
69+
HttpResponseCodes::CONFLICT,
70+
HttpResponseCodes::INTERNAL_SERVER_ERROR,
71+
HttpResponseCodes::UNAUTHORIZED,
72+
])]
73+
public function createSelectOption(
74+
#[MapRequestPayload] CreateSelectOptionParameters $parameters,
75+
): JsonResponse {
76+
return $this->jsonResponse(
77+
$this->selectOptionService->createSelectOption($parameters)
78+
);
79+
}
80+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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\SelectOptions;
15+
16+
use OpenApi\Attributes\Delete;
17+
use Pimcore\Bundle\StudioBackendBundle\Class\Service\SelectOptions\SelectOptionServiceInterface;
18+
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
19+
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\ConflictException;
20+
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\ForbiddenException;
21+
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException;
22+
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotWriteableException;
23+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Path\StringParameter;
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 Symfony\Component\HttpFoundation\Response;
30+
use Symfony\Component\Routing\Attribute\Route;
31+
use Symfony\Component\Security\Http\Attribute\IsGranted;
32+
use Symfony\Component\Serializer\SerializerInterface;
33+
34+
/**
35+
* @internal
36+
*/
37+
final class DeleteController extends AbstractApiController
38+
{
39+
private const string ROUTE = '/class/select-option/{id}';
40+
41+
public function __construct(
42+
SerializerInterface $serializer,
43+
private readonly SelectOptionServiceInterface $selectOptionService,
44+
) {
45+
parent::__construct($serializer);
46+
}
47+
48+
/**
49+
* @throws ConflictException|ForbiddenException|NotFoundException|NotWriteableException
50+
*/
51+
#[Route(self::ROUTE, name: 'pimcore_studio_api_class_select_option_delete', methods: ['DELETE'])]
52+
#[IsGranted(UserPermissions::SELECT_OPTIONS->value)]
53+
#[Delete(
54+
path: self::PREFIX . self::ROUTE,
55+
operationId: 'class_select_option_delete',
56+
description: 'class_select_option_delete_description',
57+
summary: 'class_select_option_delete_summary',
58+
tags: [Tags::ClassDefinition->value],
59+
)]
60+
#[StringParameter(
61+
name: 'id',
62+
example: 'EventStatus',
63+
description: 'Select option configuration ID',
64+
required: true
65+
)]
66+
#[SuccessResponse(
67+
description: 'class_select_option_delete_success_response'
68+
)]
69+
#[DefaultResponses([
70+
HttpResponseCodes::CONFLICT,
71+
HttpResponseCodes::FORBIDDEN,
72+
HttpResponseCodes::INTERNAL_SERVER_ERROR,
73+
HttpResponseCodes::NOT_FOUND,
74+
HttpResponseCodes::UNAUTHORIZED,
75+
])]
76+
public function deleteSelectOption(string $id): Response
77+
{
78+
$this->selectOptionService->deleteSelectOption($id);
79+
80+
return new Response();
81+
}
82+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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\SelectOptions;
15+
16+
use OpenApi\Attributes\Get;
17+
use OpenApi\Attributes\JsonContent;
18+
use Pimcore\Bundle\StudioBackendBundle\Class\Schema\SelectOption\SelectOptionDetail;
19+
use Pimcore\Bundle\StudioBackendBundle\Class\Service\SelectOptions\SelectOptionServiceInterface;
20+
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
21+
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException;
22+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Path\StringParameter;
23+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\DefaultResponses;
24+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\SuccessResponse;
25+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags;
26+
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\HttpResponseCodes;
27+
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\UserPermissions;
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+
33+
/**
34+
* @internal
35+
*/
36+
final class GetController extends AbstractApiController
37+
{
38+
private const string ROUTE = '/class/select-option/{id}';
39+
40+
public function __construct(
41+
SerializerInterface $serializer,
42+
private readonly SelectOptionServiceInterface $selectOptionService,
43+
) {
44+
parent::__construct($serializer);
45+
}
46+
47+
/**
48+
* @throws NotFoundException
49+
*/
50+
#[Route(self::ROUTE, name: 'pimcore_studio_api_class_select_option_get', methods: ['GET'])]
51+
#[IsGranted(UserPermissions::SELECT_OPTIONS->value)]
52+
#[Get(
53+
path: self::PREFIX . self::ROUTE,
54+
operationId: 'class_select_option_get',
55+
description: 'class_select_option_get_description',
56+
summary: 'class_select_option_get_summary',
57+
tags: [Tags::ClassDefinition->value],
58+
)]
59+
#[StringParameter(
60+
name: 'id',
61+
example: 'EventStatus',
62+
description: 'Select option configuration ID',
63+
required: true
64+
)]
65+
#[SuccessResponse(
66+
description: 'class_select_option_get_success_response',
67+
content: new JsonContent(ref: SelectOptionDetail::class)
68+
)]
69+
#[DefaultResponses([
70+
HttpResponseCodes::NOT_FOUND,
71+
HttpResponseCodes::UNAUTHORIZED,
72+
])]
73+
public function getSelectOption(string $id): JsonResponse
74+
{
75+
return $this->jsonResponse(
76+
$this->selectOptionService->getSelectOption($id)
77+
);
78+
}
79+
}

src/Class/Controller/SelectOptions/TreeController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use OpenApi\Attributes\Get;
1717
use Pimcore\Bundle\StudioBackendBundle\Class\Attribute\Response\Property\AnyOfSelectOptionNodes;
1818
use Pimcore\Bundle\StudioBackendBundle\Class\MappedParameter\TreeParameter;
19-
use Pimcore\Bundle\StudioBackendBundle\Class\Service\SelectOptionServiceInterface;
19+
use Pimcore\Bundle\StudioBackendBundle\Class\Service\SelectOptions\TreeServiceInterface;
2020
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
2121
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Query\BoolParameter;
2222
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\Content\CollectionJson;
@@ -44,12 +44,12 @@ final class TreeController extends AbstractApiController
4444

4545
public function __construct(
4646
SerializerInterface $serializer,
47-
private readonly SelectOptionServiceInterface $optionService,
47+
private readonly TreeServiceInterface $optionService,
4848
) {
4949
parent::__construct($serializer);
5050
}
5151

52-
#[Route(self::ROUTE, name: 'pimcore_studio_api_class_select_option_tree', methods: ['GET'])]
52+
#[Route(self::ROUTE, name: 'pimcore_studio_api_class_select_option_tree', methods: ['GET'], priority: 10)]
5353
#[IsGranted(UserPermissions::SELECT_OPTIONS->value)]
5454
#[Get(
5555
path: self::PREFIX . self::ROUTE,

0 commit comments

Comments
 (0)