-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Data Object Editor] Get Select Options Endpoint (#631)
* get select Options for Dynamic select * Apply php-cs-fixer changes * Fix style. * Apply php-cs-fixer changes * Fix style. * Fix Exception Handling. * Apply php-cs-fixer changes --------- Co-authored-by: martineiber <[email protected]>
- Loading branch information
1 parent
75dd36a
commit 7cbcc42
Showing
13 changed files
with
822 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/DataObject/Attribute/Request/SelectOptionRequestBody.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license GPLv3 and PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\StudioBackendBundle\DataObject\Attribute\Request; | ||
|
||
use Attribute; | ||
use OpenApi\Attributes\JsonContent; | ||
use OpenApi\Attributes\Property; | ||
use OpenApi\Attributes\RequestBody; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Property\SingleInteger; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Property\SingleString; | ||
|
||
#[Attribute(Attribute::TARGET_METHOD)] | ||
final class SelectOptionRequestBody extends RequestBody | ||
{ | ||
public function __construct() | ||
{ | ||
parent::__construct( | ||
required: true, | ||
content: new JsonContent( | ||
required: ['objectId', 'fieldName', 'context'], | ||
properties: [ | ||
new SingleInteger('objectId'), | ||
new SingleString('fieldName'), | ||
new Property( | ||
property: 'changedData', | ||
type: 'object', | ||
example: '{"Input":"new value"}' | ||
), | ||
new Property( | ||
property: 'context', | ||
type: 'object', | ||
example: '{"containerType":"object","fieldname":"select","objectId":40,"layoutId":"0"}' | ||
), | ||
] | ||
) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license GPLv3 and PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\StudioBackendBundle\DataObject\Controller; | ||
|
||
use OpenApi\Attributes\Post; | ||
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController; | ||
use Pimcore\Bundle\StudioBackendBundle\DataObject\Attribute\Request\SelectOptionRequestBody; | ||
use Pimcore\Bundle\StudioBackendBundle\DataObject\MappedParameter\SelectOptionsParameter; | ||
use Pimcore\Bundle\StudioBackendBundle\DataObject\Schema\SelectOption; | ||
use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\SelectOptionsServiceInterface; | ||
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\DatabaseException; | ||
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidArgumentException; | ||
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Property\GenericCollection; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\Content\CollectionJson; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\DefaultResponses; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\SuccessResponse; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags; | ||
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\HttpResponseCodes; | ||
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\UserPermissions; | ||
use Pimcore\Bundle\StudioBackendBundle\Util\Trait\PaginatedResponseTrait; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpKernel\Attribute\MapRequestPayload; | ||
use Symfony\Component\Routing\Attribute\Route; | ||
use Symfony\Component\Security\Http\Attribute\IsGranted; | ||
use Symfony\Component\Serializer\SerializerInterface; | ||
use function count; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class SelectOptionsController extends AbstractApiController | ||
{ | ||
use PaginatedResponseTrait; | ||
|
||
public function __construct( | ||
SerializerInterface $serializer, | ||
private readonly SelectOptionsServiceInterface $selectOptionsService, | ||
) { | ||
parent::__construct($serializer); | ||
} | ||
|
||
/** | ||
* @throws DatabaseException | ||
* @throws NotFoundException | ||
* @throws InvalidArgumentException | ||
*/ | ||
#[Route( | ||
path: '/data-objects/select-options', | ||
name: 'pimcore_studio_api_get_data_object_get_select_options', | ||
methods: ['POST'] | ||
)] | ||
#[IsGranted(UserPermissions::DATA_OBJECTS->value)] | ||
#[Post( | ||
path: self::PREFIX . '/data-objects/select-options', | ||
operationId: 'data_object_get_select_options', | ||
description: 'data_object_get_select_options_description', | ||
summary: 'data_object_get_select_options_summary', | ||
tags: [Tags::DataObjects->value] | ||
)] | ||
#[SelectOptionRequestBody] | ||
#[SuccessResponse( | ||
description: 'data_object_get_select_options_success_response', | ||
content: new CollectionJson(new GenericCollection(SelectOption::class)) | ||
)] | ||
#[DefaultResponses([ | ||
HttpResponseCodes::UNAUTHORIZED, | ||
HttpResponseCodes::NOT_FOUND, | ||
HttpResponseCodes::BAD_REQUEST, | ||
])] | ||
public function getSelectOptions(#[MapRequestPayload] SelectOptionsParameter $selectOptionsParameter): JsonResponse | ||
{ | ||
$selectOptions = $this->selectOptionsService->getSelectOptions($selectOptionsParameter); | ||
|
||
return $this->getPaginatedCollection( | ||
$this->serializer, | ||
$selectOptions, | ||
count($selectOptions), | ||
); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/DataObject/Event/PreResponse/DynamicSelectOptionEvent.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license GPLv3 and PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\StudioBackendBundle\DataObject\Event\PreResponse; | ||
|
||
use Pimcore\Bundle\StudioBackendBundle\DataObject\Schema\SelectOption; | ||
use Pimcore\Bundle\StudioBackendBundle\Event\AbstractPreResponseEvent; | ||
|
||
final class DynamicSelectOptionEvent extends AbstractPreResponseEvent | ||
{ | ||
public const EVENT_NAME = 'pre_response.data_object.dynamic_select_option'; | ||
|
||
public function __construct( | ||
private readonly SelectOption $selectOption | ||
) { | ||
parent::__construct($this->selectOption); | ||
} | ||
|
||
/** | ||
* Use this to get additional infos out of the response object | ||
*/ | ||
public function getSelectOption(): SelectOption | ||
{ | ||
return $this->selectOption; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license GPLv3 and PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\StudioBackendBundle\DataObject\Hydrator; | ||
|
||
use Pimcore\Bundle\StudioBackendBundle\DataObject\Schema\SelectOption; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final readonly class SelectOptionHydrator implements SelectOptionHydratorInterface | ||
{ | ||
public function hydrate(array $data): SelectOption | ||
{ | ||
return new SelectOption( | ||
key: $data['key'], | ||
value: $data['value'] | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license GPLv3 and PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\StudioBackendBundle\DataObject\Hydrator; | ||
|
||
use Pimcore\Bundle\StudioBackendBundle\DataObject\Schema\SelectOption; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
interface SelectOptionHydratorInterface | ||
{ | ||
public function hydrate(array $data): SelectOption; | ||
} |
Oops, something went wrong.