-
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.
[DataObject]: Add endpoint to list data object layouts (#520)
* feat: add endpoint to list data object layouts * Apply php-cs-fixer changes --------- Co-authored-by: lukmzig <[email protected]>
- Loading branch information
Showing
10 changed files
with
462 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
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
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,80 @@ | ||
<?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\Get; | ||
use OpenApi\Attributes\JsonContent; | ||
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController; | ||
use Pimcore\Bundle\StudioBackendBundle\DataObject\Schema\Layout; | ||
use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\LayoutServiceInterface; | ||
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\AccessDeniedException; | ||
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidElementTypeException; | ||
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException; | ||
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\UserNotFoundException; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Path\IdParameter; | ||
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 Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\Routing\Attribute\Route; | ||
use Symfony\Component\Security\Http\Attribute\IsGranted; | ||
use Symfony\Component\Serializer\SerializerInterface; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class LayoutController extends AbstractApiController | ||
{ | ||
public function __construct( | ||
SerializerInterface $serializer, | ||
private readonly LayoutServiceInterface $layoutService, | ||
) { | ||
parent::__construct($serializer); | ||
} | ||
|
||
/** | ||
* @throws AccessDeniedException|InvalidElementTypeException|NotFoundException|UserNotFoundException | ||
*/ | ||
#[Route( | ||
path: '/data-objects/{id}/layout', | ||
name: 'pimcore_studio_api_get_data_object_layout', | ||
methods: ['GET'] | ||
)] | ||
#[IsGranted(UserPermissions::DATA_OBJECTS->value)] | ||
#[Get( | ||
path: self::PREFIX . '/data-objects/{id}/layout', | ||
operationId: 'data_object_get_layout_by_id', | ||
description: 'data_object_get_layout_by_id_description', | ||
summary: 'data_object_get_layout_by_id_summary', | ||
tags: [Tags::DataObjects->value] | ||
)] | ||
#[IdParameter(type: 'data-object')] | ||
#[SuccessResponse( | ||
description: 'data_object_get_layout_by_id_success_response', | ||
content: new JsonContent(ref: Layout::class) | ||
)] | ||
#[DefaultResponses([ | ||
HttpResponseCodes::UNAUTHORIZED, | ||
HttpResponseCodes::NOT_FOUND, | ||
])] | ||
public function getDataObjectLayoutById(int $id): JsonResponse | ||
{ | ||
return $this->jsonResponse($this->layoutService->getDataObjectLayout($id)); | ||
} | ||
} |
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\Layout; | ||
use Pimcore\Bundle\StudioBackendBundle\Event\AbstractPreResponseEvent; | ||
|
||
final class LayoutEvent extends AbstractPreResponseEvent | ||
{ | ||
public const EVENT_NAME = 'pre_response.data_object.layout'; | ||
|
||
public function __construct( | ||
private readonly Layout $layout | ||
) { | ||
parent::__construct($this->layout); | ||
} | ||
|
||
/** | ||
* Use this to get additional infos out of the response object | ||
*/ | ||
public function getLayout(): Layout | ||
{ | ||
return $this->layout; | ||
} | ||
} |
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,183 @@ | ||
<?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\Schema; | ||
|
||
use OpenApi\Attributes\Items; | ||
use OpenApi\Attributes\Property; | ||
use OpenApi\Attributes\Schema; | ||
use Pimcore\Bundle\StudioBackendBundle\Response\ElementIcon; | ||
use Pimcore\Bundle\StudioBackendBundle\Util\Schema\AdditionalAttributesInterface; | ||
use Pimcore\Bundle\StudioBackendBundle\Util\Trait\AdditionalAttributesTrait; | ||
|
||
#[Schema( | ||
title: 'Layout', | ||
required: [ | ||
'name', | ||
'dataType', | ||
'fieldType', | ||
'type', | ||
'layout', | ||
'region', | ||
'title', | ||
'width', | ||
'height', | ||
'collapsible', | ||
'collapsed', | ||
'bodyStyle', | ||
'locked', | ||
'children', | ||
'icon', | ||
'labelAlign', | ||
'labelWidth', | ||
'border', | ||
], | ||
type: 'object' | ||
)] | ||
class Layout implements AdditionalAttributesInterface | ||
{ | ||
use AdditionalAttributesTrait; | ||
|
||
public function __construct( | ||
#[Property(description: 'Name', type: 'string', example: 'pimcore_root')] | ||
private readonly string $name, | ||
#[Property(description: 'Data Type', type: 'string', example: 'layout')] | ||
private readonly string $dataType, | ||
#[Property(description: 'Field Type', type: 'string', example: 'panel')] | ||
private readonly string $fieldType, | ||
#[Property(description: 'Type', type: 'string', example: null)] | ||
private readonly ?string $type = null, | ||
#[Property(description: 'Layout', type: 'string', example: null)] | ||
private readonly ?string $layout = null, | ||
#[Property(description: 'Region', type: 'string', example: 'center')] | ||
private readonly ?string $region = null, | ||
#[Property(description: 'Title', type: 'string', example: 'MyLayout')] | ||
private readonly ?string $title = null, | ||
#[Property(description: 'Width', type: 'integer', example: 0)] | ||
private readonly int $width = 0, | ||
#[Property(description: 'Height', type: 'integer', example: 0)] | ||
private readonly int $height = 0, | ||
#[Property(description: 'Collapsible', type: 'bool', example: false)] | ||
private readonly bool $collapsible = false, | ||
#[Property(description: 'Collapsed', type: 'bool', example: false)] | ||
private readonly bool $collapsed = false, | ||
#[Property(description: 'Body Style', type: 'string', example: '(float: left;)')] | ||
private readonly ?string $bodyStyle = null, | ||
#[Property(description: 'Locked', type: 'bool', example: false)] | ||
private readonly bool $locked = false, | ||
#[Property(description: 'Children', type: 'array', items: new Items(), example: '[]')] | ||
private readonly array $children = [], | ||
#[Property(description: 'Icon', type: ElementIcon::class)] | ||
private readonly ?ElementIcon $icon = null, | ||
#[Property(description: 'Label Align', type: 'string', example: 'left')] | ||
private readonly string $labelAlign = 'left', | ||
#[Property(description: 'Label Width', type: 'integer', example: 100)] | ||
private readonly int $labelWidth = 100, | ||
#[Property(description: 'Border', type: 'bool', example: false)] | ||
private readonly bool $border = false, | ||
) { | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
public function getTitle(): ?string | ||
{ | ||
return $this->title; | ||
} | ||
|
||
public function getDataType(): string | ||
{ | ||
return $this->dataType; | ||
} | ||
|
||
public function getFieldType(): string | ||
{ | ||
return $this->fieldType; | ||
} | ||
|
||
public function getType(): ?string | ||
{ | ||
return $this->type; | ||
} | ||
|
||
public function getLayout(): ?string | ||
{ | ||
return $this->layout; | ||
} | ||
|
||
public function getRegion(): ?string | ||
{ | ||
return $this->region; | ||
} | ||
|
||
public function getWidth(): int | ||
{ | ||
return $this->width; | ||
} | ||
|
||
public function getHeight(): int | ||
{ | ||
return $this->height; | ||
} | ||
|
||
public function getCollapsible(): bool | ||
{ | ||
return $this->collapsible; | ||
} | ||
|
||
public function getCollapsed(): bool | ||
{ | ||
return $this->collapsed; | ||
} | ||
|
||
public function getBodyStyle(): ?string | ||
{ | ||
return $this->bodyStyle; | ||
} | ||
|
||
public function getBorder(): bool | ||
{ | ||
return $this->border; | ||
} | ||
|
||
public function getIcon(): ?ElementIcon | ||
{ | ||
return $this->icon; | ||
} | ||
|
||
public function getLabelWidth(): int | ||
{ | ||
return $this->labelWidth; | ||
} | ||
|
||
public function getLabelAlign(): string | ||
{ | ||
return $this->labelAlign; | ||
} | ||
|
||
public function getLocked(): bool | ||
{ | ||
return $this->locked; | ||
} | ||
|
||
public function getChildren(): array | ||
{ | ||
return $this->children; | ||
} | ||
} |
Oops, something went wrong.