Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Data Object Editor] Add Endpoint to get objectbrick layout #601

Merged
merged 14 commits into from
Dec 2, 2024
8 changes: 7 additions & 1 deletion config/class.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ services:
Pimcore\Bundle\StudioBackendBundle\Class\Service\FieldCollection\LayoutDefinitionServiceInterface:
class: Pimcore\Bundle\StudioBackendBundle\Class\Service\FieldCollection\LayoutDefinitionService

Pimcore\Bundle\StudioBackendBundle\Class\Service\ObjectBrick\LayoutDefinitionServiceInterface:
class: Pimcore\Bundle\StudioBackendBundle\Class\Service\ObjectBrick\LayoutDefinitionService

Pimcore\Bundle\StudioBackendBundle\Class\Repository\QuantityValueRepositoryInterface:
class: Pimcore\Bundle\StudioBackendBundle\Class\Repository\QuantityValueRepository

Expand All @@ -27,4 +30,7 @@ services:
# Hydrators
#
Pimcore\Bundle\StudioBackendBundle\Class\Hydrator\FieldCollection\LayoutDefinitionHydratorInterface:
class: Pimcore\Bundle\StudioBackendBundle\Class\Hydrator\FieldCollection\LayoutDefinitionHydrator
class: Pimcore\Bundle\StudioBackendBundle\Class\Hydrator\FieldCollection\LayoutDefinitionHydrator

Pimcore\Bundle\StudioBackendBundle\Class\Hydrator\ObjectBrick\LayoutDefinitionHydratorInterface:
class: Pimcore\Bundle\StudioBackendBundle\Class\Hydrator\ObjectBrick\LayoutDefinitionHydrator
2 changes: 1 addition & 1 deletion src/Class/Controller/FieldCollection/LayoutController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use Exception;
use OpenApi\Attributes\Get;
use Pimcore\Bundle\StudioBackendBundle\Class\Schema\LayoutDefinition;
use Pimcore\Bundle\StudioBackendBundle\Class\Schema\FieldCollection\LayoutDefinition;
use Pimcore\Bundle\StudioBackendBundle\Class\Service\FieldCollection\LayoutDefinitionServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException;
Expand Down
82 changes: 82 additions & 0 deletions src/Class/Controller/ObjectBrick/LayoutController.php
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),
);
}
}
2 changes: 1 addition & 1 deletion src/Class/Event/FieldCollection/LayoutDefinitionEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace Pimcore\Bundle\StudioBackendBundle\Class\Event\FieldCollection;

use Pimcore\Bundle\StudioBackendBundle\Class\Schema\LayoutDefinition;
use Pimcore\Bundle\StudioBackendBundle\Class\Schema\FieldCollection\LayoutDefinition;
use Pimcore\Bundle\StudioBackendBundle\Event\AbstractPreResponseEvent;

final class LayoutDefinitionEvent extends AbstractPreResponseEvent
Expand Down
35 changes: 35 additions & 0 deletions src/Class/Event/ObjectBrick/LayoutDefinitionEvent.php
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace Pimcore\Bundle\StudioBackendBundle\Class\Hydrator\FieldCollection;

use Pimcore\Bundle\StudioBackendBundle\Class\Schema\LayoutDefinition;
use Pimcore\Bundle\StudioBackendBundle\Class\Schema\FieldCollection\LayoutDefinition;
use Pimcore\Model\DataObject\Fieldcollection\Definition as FieldCollectionDefinition;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace Pimcore\Bundle\StudioBackendBundle\Class\Hydrator\FieldCollection;

use Pimcore\Bundle\StudioBackendBundle\Class\Schema\LayoutDefinition;
use Pimcore\Bundle\StudioBackendBundle\Class\Schema\FieldCollection\LayoutDefinition;
use Pimcore\Model\DataObject\Fieldcollection\Definition as FieldCollectionDefinition;

/**
Expand Down
45 changes: 45 additions & 0 deletions src/Class/Hydrator/ObjectBrick/LayoutDefinitionHydrator.php
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(),
);
}
}
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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioBackendBundle\Class\Schema;
namespace Pimcore\Bundle\StudioBackendBundle\Class\Schema\FieldCollection;

use OpenApi\Attributes\Items;
use OpenApi\Attributes\Property;
Expand All @@ -26,6 +26,7 @@
* @internal
*/
#[Schema(
schema: 'FieldCollectionLayoutDefinition',
title: 'Field Collection Layout Definition',
required: [
'key',
Expand Down
127 changes: 127 additions & 0 deletions src/Class/Schema/ObjectBrick/LayoutDefinition.php
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;
}
}
Loading
Loading