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

[DataObject]: Add endpoint to list data object layouts #520

Merged
merged 2 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions config/data_objects.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ services:
Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterLoaderInterface:
class: Pimcore\Bundle\StudioBackendBundle\DataObject\Service\Loader\TaggedIteratorDataAdapter

Pimcore\Bundle\StudioBackendBundle\DataObject\Service\LayoutServiceInterface:
class: Pimcore\Bundle\StudioBackendBundle\DataObject\Service\LayoutService

#
# Data Adapters
#
Expand Down Expand Up @@ -161,6 +164,7 @@ services:

Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Adapter\FieldCollectionsAdapter:
tags: [ 'pimcore.studio_backend.data_adapter' ]

#
# Handler
#
Expand Down
2 changes: 1 addition & 1 deletion src/DataIndex/Hydrator/HydratorService.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function hydrateDataObjects(DataObjectSearchResultItem $item): DataObject
return $this->dataObjectHydrator->hydrate($item);
}

public function hydradeDocuments(DocumentSearchResultItem $item): IndexDocument
public function hydrateDocuments(DocumentSearchResultItem $item): IndexDocument
{
// TODO: Add Service Locator for different document types

Expand Down
80 changes: 80 additions & 0 deletions src/DataObject/Controller/LayoutController.php
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));
}
}
39 changes: 39 additions & 0 deletions src/DataObject/Event/PreResponse/LayoutEvent.php
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;
}
}
183 changes: 183 additions & 0 deletions src/DataObject/Schema/Layout.php
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;
}
}
Loading
Loading