-
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] Add Endpoint to get objectbrick layout (#601)
* Fix Return Type. * Get Layout Definition for Object Bricks. * Add translation. * Fix schema * Apply php-cs-fixer changes * Add return type * Apply php-cs-fixer changes * Fix line length. * Apply php-cs-fixer changes * Fix return Value. * Fix Return Value * Import namespace. * Apply php-cs-fixer changes --------- Co-authored-by: martineiber <martineiber@users.noreply.github.com>
- Loading branch information
1 parent
1071eff
commit dfb8817
Showing
16 changed files
with
470 additions
and
9 deletions.
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,82 @@ | ||
<?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\Class\Controller\ObjectBrick; | ||
|
||
use Exception; | ||
use OpenApi\Attributes\Get; | ||
use Pimcore\Bundle\StudioBackendBundle\Class\Schema\ObjectBrick\LayoutDefinition; | ||
use Pimcore\Bundle\StudioBackendBundle\Class\Service\ObjectBrick\LayoutDefinitionServiceInterface; | ||
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController; | ||
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Path\IdParameter; | ||
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\Trait\PaginatedResponseTrait; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\Routing\Attribute\Route; | ||
use Symfony\Component\Serializer\SerializerInterface; | ||
use function count; | ||
|
||
final class LayoutController extends AbstractApiController | ||
{ | ||
use PaginatedResponseTrait; | ||
|
||
public function __construct( | ||
SerializerInterface $serializer, | ||
private readonly LayoutDefinitionServiceInterface $layoutDefinitionService, | ||
) { | ||
parent::__construct($serializer); | ||
} | ||
|
||
/** | ||
* @throws Exception|NotFoundException | ||
*/ | ||
#[Route( | ||
'/class/object-brick/{objectId}/object/layout', | ||
name: 'pimcore_studio_api_class_object_brick_object_layout', | ||
methods: ['GET'] | ||
)] | ||
#[Get( | ||
path: self::PREFIX . '/class/object-brick/{objectId}/object/layout', | ||
operationId: 'class_object_brick_object_layout', | ||
description: 'class_object_brick_object_layout_description', | ||
summary: 'class_object_brick_object_layout_summary', | ||
tags: [Tags::ClassDefinition->value], | ||
)] | ||
#[IdParameter(name: 'objectId', required: true)] | ||
#[SuccessResponse( | ||
description: 'class_object_brick_object_layout_success_response', | ||
content: new CollectionJson(new GenericCollection(LayoutDefinition::class)) | ||
)] | ||
#[DefaultResponses([ | ||
HttpResponseCodes::NOT_FOUND, | ||
])] | ||
public function getObjectBrickLayoutForObject(int $objectId): JsonResponse | ||
{ | ||
$items = $this->layoutDefinitionService->getLayoutDefinitionsForObject($objectId); | ||
|
||
return $this->getPaginatedCollection( | ||
$this->serializer, | ||
$items, | ||
count($items), | ||
); | ||
} | ||
} |
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,35 @@ | ||
<?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\Class\Event\ObjectBrick; | ||
|
||
use Pimcore\Bundle\StudioBackendBundle\Class\Schema\ObjectBrick\LayoutDefinition; | ||
use Pimcore\Bundle\StudioBackendBundle\Event\AbstractPreResponseEvent; | ||
|
||
final class LayoutDefinitionEvent extends AbstractPreResponseEvent | ||
{ | ||
public const EVENT_NAME = 'pre_response.objectBrick.layout_definition'; | ||
|
||
public function __construct(private readonly LayoutDefinition $layoutDefinition) | ||
{ | ||
parent::__construct($this->layoutDefinition); | ||
} | ||
|
||
public function getLayoutDefinition(): LayoutDefinition | ||
{ | ||
return $this->layoutDefinition; | ||
} | ||
} |
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
45 changes: 45 additions & 0 deletions
45
src/Class/Hydrator/ObjectBrick/LayoutDefinitionHydrator.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,45 @@ | ||
<?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\Class\Hydrator\ObjectBrick; | ||
|
||
use Pimcore\Bundle\StudioBackendBundle\Class\Schema\ObjectBrick\LayoutDefinition; | ||
use Pimcore\Model\DataObject\Objectbrick\Definition as ObjectBrickDefinition; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class LayoutDefinitionHydrator implements LayoutDefinitionHydratorInterface | ||
{ | ||
public function hydrate(ObjectBrickDefinition $data): LayoutDefinition | ||
{ | ||
$layout = $data->getLayoutDefinitions(); | ||
|
||
return new LayoutDefinition( | ||
$data->getKey(), | ||
$layout->getDatatype(), | ||
$layout->getName(), | ||
$layout->getType(), | ||
$layout->getRegion(), | ||
$layout->getTitle(), | ||
$layout->getWidth(), | ||
$layout->getHeight(), | ||
$layout->getCollapsible(), | ||
$layout->getCollapsed(), | ||
$layout->getChildren(), | ||
); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/Class/Hydrator/ObjectBrick/LayoutDefinitionHydratorInterface.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,28 @@ | ||
<?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\Class\Hydrator\ObjectBrick; | ||
|
||
use Pimcore\Bundle\StudioBackendBundle\Class\Schema\ObjectBrick\LayoutDefinition; | ||
use Pimcore\Model\DataObject\Objectbrick\Definition as ObjectBrickDefinition; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
interface LayoutDefinitionHydratorInterface | ||
{ | ||
public function hydrate(ObjectBrickDefinition $data): LayoutDefinition; | ||
} |
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,127 @@ | ||
<?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\Class\Schema\ObjectBrick; | ||
|
||
use OpenApi\Attributes\Items; | ||
use OpenApi\Attributes\Property; | ||
use OpenApi\Attributes\Schema; | ||
use Pimcore\Bundle\StudioBackendBundle\Util\Schema\AdditionalAttributesInterface; | ||
use Pimcore\Bundle\StudioBackendBundle\Util\Trait\AdditionalAttributesTrait; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
#[Schema( | ||
schema: 'ObjectBrickLayoutDefinition', | ||
title: 'Object Brick Layout Definition', | ||
required: [ | ||
'key', | ||
'title', | ||
'width', | ||
'height', | ||
'collapsible', | ||
'collapsed', | ||
'datatype', | ||
'children', | ||
], | ||
type: 'object' | ||
)] | ||
final class LayoutDefinition implements AdditionalAttributesInterface | ||
{ | ||
use AdditionalAttributesTrait; | ||
|
||
public function __construct( | ||
#[Property(description: 'Key of Object Brick', type: 'string')] | ||
private readonly string $key, | ||
#[Property(description: 'Data Type', type: 'string', example: 'layout')] | ||
private readonly string $datatype, | ||
#[Property(description: 'Name', type: 'string', example: 'Layout')] | ||
private readonly ?string $name = null, | ||
#[Property(description: 'Type', type: 'string')] | ||
private readonly ?string $type = null, | ||
#[Property(description: 'Region', type: 'string')] | ||
private readonly ?string $region = null, | ||
#[Property(description: 'Title', type: 'string')] | ||
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: 'boolean', example: false)] | ||
private readonly bool $collapsible = false, | ||
#[Property(description: 'collapsed', type: 'boolean', example: false)] | ||
private readonly bool $collapsed = false, | ||
#[Property(description: 'Children', type: 'array', items: new Items(), example: '[]')] | ||
private readonly array $children = [], | ||
) { | ||
} | ||
|
||
public function getKey(): string | ||
{ | ||
return $this->key; | ||
} | ||
|
||
public function getName(): ?string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
public function getType(): ?string | ||
{ | ||
return $this->type; | ||
} | ||
|
||
public function getRegion(): ?string | ||
{ | ||
return $this->region; | ||
} | ||
|
||
public function getTitle(): ?string | ||
{ | ||
return $this->title; | ||
} | ||
|
||
public function getWidth(): int | ||
{ | ||
return $this->width; | ||
} | ||
|
||
public function getHeight(): int | ||
{ | ||
return $this->height; | ||
} | ||
|
||
public function isCollapsible(): bool | ||
{ | ||
return $this->collapsible; | ||
} | ||
|
||
public function isCollapsed(): bool | ||
{ | ||
return $this->collapsed; | ||
} | ||
|
||
public function getDatatype(): string | ||
{ | ||
return $this->datatype; | ||
} | ||
|
||
public function getChildren(): array | ||
{ | ||
return $this->children; | ||
} | ||
} |
Oops, something went wrong.