Skip to content
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
6 changes: 6 additions & 0 deletions config/class.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ services:
Pimcore\Bundle\StudioBackendBundle\Class\Service\LayoutServiceInterface:
class: Pimcore\Bundle\StudioBackendBundle\Class\Service\LayoutService

Pimcore\Bundle\StudioBackendBundle\Class\Service\FieldsByTypeServiceInterface:
class: Pimcore\Bundle\StudioBackendBundle\Class\Service\FieldsByTypeService

#
# Repositories
#
Expand Down Expand Up @@ -108,6 +111,9 @@ services:
Pimcore\Bundle\StudioBackendBundle\Class\Hydrator\ObjectBrick\ObjectBrickConfigHydratorInterface:
class: Pimcore\Bundle\StudioBackendBundle\Class\Hydrator\ObjectBrick\ObjectBrickConfigHydrator

Pimcore\Bundle\StudioBackendBundle\Class\Hydrator\FieldByTypeHydratorInterface:
class: Pimcore\Bundle\StudioBackendBundle\Class\Hydrator\FieldByTypeHydrator

Pimcore\Bundle\StudioBackendBundle\Class\Hydrator\CompactLayoutHydratorInterface:
class: Pimcore\Bundle\StudioBackendBundle\Class\Hydrator\CompactLayoutHydrator

Expand Down
1 change: 1 addition & 0 deletions doc/05_Additional_Custom_Attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ final class AssetEvent extends AbstractPreResponseEvent
- `pre_response.class_definition.identifier_data`
- `pre_response.class_definition.object_brick_data`
- `pre_response.class_definition.tree`
- `pre_response.class_field_by_type`
- `pre_response.classification_store.collection`
- `pre_response.classification_store.config_collection`
- `pre_response.classification_store.group`
Expand Down
4 changes: 2 additions & 2 deletions src/Class/Attribute/Request/CustomLayoutUpdateRequestBody.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
#[Attribute(Attribute::TARGET_METHOD)]
final class CustomLayoutUpdateRequestBody extends RequestBody
{
public function __construct()
public function __construct(bool $required = true)
{
parent::__construct(
required: true,
required: $required,
content: new JsonContent(
ref: CustomLayoutUpdate::class,
type: 'object'
Expand Down
1 change: 1 addition & 0 deletions src/Class/Controller/CollectionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public function listClasses(): JsonResponse
new PermissionsToCheck([
UserPermissions::CLASS_DEFINITION->value,
UserPermissions::DATA_OBJECTS->value,
UserPermissions::OBJECT_BRICKS->value,
UserPermissions::USER_MANAGEMENT->value,
])
);
Expand Down
31 changes: 18 additions & 13 deletions src/Class/Controller/CustomLayout/ClassCollectionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
namespace Pimcore\Bundle\StudioBackendBundle\Class\Controller\CustomLayout;

use OpenApi\Attributes\Get;
use Pimcore\Bundle\StudioBackendBundle\Class\MappedParameter\ClassIdsParameters;
use Pimcore\Bundle\StudioBackendBundle\Class\Schema\CustomLayout\CustomLayoutCompact;
use Pimcore\Bundle\StudioBackendBundle\Class\Service\CustomLayoutServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Path\StringParameter;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Query\ClassIdsParameter;
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;
Expand All @@ -27,15 +28,21 @@
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\UserPermissions;
use Pimcore\Bundle\StudioBackendBundle\Util\Trait\PaginatedResponseTrait;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpKernel\Attribute\MapQueryString;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
use Symfony\Component\Serializer\SerializerInterface;
use function count;

/**
* @internal
*/
final class ClassCollectionController extends AbstractApiController
{
use PaginatedResponseTrait;

private const string ROUTE = '/class/custom-layout/collection';

public function __construct(
SerializerInterface $serializer,
private readonly CustomLayoutServiceInterface $customLayoutService
Expand All @@ -44,34 +51,32 @@ public function __construct(
}

#[Route(
'/class/custom-layout/collection/{dataObjectClass}',
self::ROUTE,
name: 'pimcore_studio_api_class_custom_layout_collection',
methods: ['GET']
methods: ['GET'],
)]
#[IsGranted(UserPermissions::DATA_OBJECTS->value)]
#[Get(
path: self::PREFIX . '/class/custom-layout/collection/{dataObjectClass}',
path: self::PREFIX . self::ROUTE,
operationId: 'class_custom_layout_collection',
description: 'class_custom_layout_collection_description',
summary: 'class_custom_layout_collection_summary',
tags: [Tags::ClassDefinition->value],
)]
#[StringParameter(
name: 'dataObjectClass',
example: 'CAR',
description: 'class_custom_layout_collection_data_object_class',
required: true
)]
#[ClassIdsParameter]
#[SuccessResponse(
description: 'class_custom_layout_collection_success_response',
content: new CollectionJson(new GenericCollection(CustomLayoutCompact::class))
)]
#[DefaultResponses([
HttpResponseCodes::UNAUTHORIZED,
])]
public function getCustomLayoutsByClass(string $dataObjectClass): JsonResponse
{
$items = $this->customLayoutService->getCustomLayoutCollection($dataObjectClass);
public function getCustomLayoutsByClass(
#[MapQueryString] ClassIdsParameters $parameters = new ClassIdsParameters()
): JsonResponse {
$items = $this->customLayoutService->getCustomLayoutCollection(
$parameters->getClassIdsArray()
);

return $this->getPaginatedCollection(
$this->serializer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Pimcore\Bundle\StudioBackendBundle\Class\Service\ClassDefinitionServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException;
use Pimcore\Bundle\StudioBackendBundle\Export\Service\DownloadServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Path\StringParameter;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\Content\MediaType;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\DefaultResponses;
Expand All @@ -38,6 +39,7 @@ final class ExportController extends AbstractApiController
public function __construct(
SerializerInterface $serializer,
private readonly ClassDefinitionServiceInterface $classDefinitionService,
private readonly DownloadServiceInterface $downloadService,
) {
parent::__construct($serializer);
}
Expand Down Expand Up @@ -75,6 +77,11 @@ public function __construct(
])]
public function exportClassDefinitionById(string $id): Response
{
return $this->classDefinitionService->exportClassDefinition($id);
$export = $this->classDefinitionService->exportClassDefinition($id);

return $this->downloadService->downloadJSON(
$export->getJson(),
$export->getFileName()
);
}
}
9 changes: 8 additions & 1 deletion src/Class/Controller/FieldCollection/ExportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Pimcore\Bundle\StudioBackendBundle\Class\Service\FieldCollection\FieldCollectionServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException;
use Pimcore\Bundle\StudioBackendBundle\Export\Service\DownloadServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Path\StringParameter;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\Content\MediaType;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\DefaultResponses;
Expand All @@ -41,6 +42,7 @@ final class ExportController extends AbstractApiController
public function __construct(
SerializerInterface $serializer,
private readonly FieldCollectionServiceInterface $fieldCollectionService,
private readonly DownloadServiceInterface $downloadService,
) {
parent::__construct($serializer);
}
Expand Down Expand Up @@ -78,6 +80,11 @@ public function __construct(
])]
public function exportFieldCollection(string $key): Response
{
return $this->fieldCollectionService->exportFieldCollection($key);
$export = $this->fieldCollectionService->exportFieldCollection($key);

return $this->downloadService->downloadJSON(
$export->getJson(),
$export->getFileName()
);
}
}
93 changes: 93 additions & 0 deletions src/Class/Controller/FieldsByTypeController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php
declare(strict_types=1);

/**
* This source file is available under the terms of the
* Pimcore Open Core License (POCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (https://www.pimcore.com)
* @license Pimcore Open Core License (POCL)
*/

namespace Pimcore\Bundle\StudioBackendBundle\Class\Controller;

use OpenApi\Attributes\Get;
use Pimcore\Bundle\StudioBackendBundle\Class\MappedParameter\FieldsByTypeParameters;
use Pimcore\Bundle\StudioBackendBundle\Class\Schema\FieldByType;
use Pimcore\Bundle\StudioBackendBundle\Class\Service\FieldsByTypeServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Query\StringParameter;
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\MapQueryString;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
use Symfony\Component\Serializer\SerializerInterface;
use function count;

/**
* @internal
*/
final class FieldsByTypeController extends AbstractApiController
{
use PaginatedResponseTrait;

private const string ROUTE = '/class/definition/fields-by-type';

public function __construct(

Check notice on line 46 in src/Class/Controller/FieldsByTypeController.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/Class/Controller/FieldsByTypeController.php#L46

Expected 2 blank lines before function; 1 found
SerializerInterface $serializer,
private readonly FieldsByTypeServiceInterface $fieldsByTypeService,
) {
parent::__construct($serializer);
}

Check notice on line 51 in src/Class/Controller/FieldsByTypeController.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/Class/Controller/FieldsByTypeController.php#L51

Expected 1 blank line before closing function brace; 0 found

Check notice on line 51 in src/Class/Controller/FieldsByTypeController.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/Class/Controller/FieldsByTypeController.php#L51

Expected 2 blank lines after function; 1 found

#[Route(
self::ROUTE,
name: 'pimcore_studio_api_class_fields_by_type',
methods: ['GET']
)]
#[IsGranted(UserPermissions::CLASS_DEFINITION->value)]
#[Get(
path: self::PREFIX . self::ROUTE,
operationId: 'class_get_fields_by_type',
description: 'class_get_fields_by_type_description',
summary: 'class_get_fields_by_type_summary',
tags: [Tags::ClassDefinition->value],
)]
#[StringParameter(
name: 'classId',
example: 'EV',
description: 'The class ID to retrieve fields for.',
required: true
)]
#[StringParameter(
name: 'type',
example: 'manyToOneRelation,objectbricks',
description: 'Comma-separated list of field types to filter by.',
required: true
)]
#[SuccessResponse(
description: 'class_get_fields_by_type_success_response',
content: new CollectionJson(new GenericCollection(FieldByType::class))
)]
#[DefaultResponses([
HttpResponseCodes::UNAUTHORIZED,
HttpResponseCodes::NOT_FOUND,
])]
public function getFieldsByType(
#[MapQueryString] FieldsByTypeParameters $parameters
): JsonResponse {
$fields = $this->fieldsByTypeService->getFieldsByType($parameters);

return $this->getPaginatedCollection($this->serializer, $fields, count($fields));
}
}
6 changes: 3 additions & 3 deletions src/Class/Controller/Folder/CollectionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

use OpenApi\Attributes\Get;
use Pimcore\Bundle\StudioBackendBundle\Class\Schema\Folder\ClassDefinitionFolderItem;
use Pimcore\Bundle\StudioBackendBundle\Class\Service\ClassDefinitionServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\Class\Service\ClassDefinitionTreeServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Path\IdParameter;
Expand Down Expand Up @@ -43,7 +43,7 @@ final class CollectionController extends AbstractApiController

public function __construct(
SerializerInterface $serializer,
private readonly ClassDefinitionServiceInterface $classDefinitionService,
private readonly ClassDefinitionTreeServiceInterface $classDefinitionTreeService,

) {
parent::__construct($serializer);
Expand Down Expand Up @@ -78,7 +78,7 @@ public function __construct(
public function getFolderClassList(
int $folderId
): JsonResponse {
$collection = $this->classDefinitionService->getClassDefinitionIdsInsideFolder($folderId);
$collection = $this->classDefinitionTreeService->getClassDefinitionIdsInsideFolder($folderId);

return $this->getPaginatedCollection(
$this->serializer,
Expand Down
81 changes: 81 additions & 0 deletions src/Class/Controller/ObjectBrick/ClassesController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php
declare(strict_types=1);

/**
* This source file is available under the terms of the
* Pimcore Open Core License (POCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (https://www.pimcore.com)
* @license Pimcore Open Core License (POCL)
*/

namespace Pimcore\Bundle\StudioBackendBundle\Class\Controller\ObjectBrick;

use OpenApi\Attributes\Get;
use Pimcore\Bundle\StudioBackendBundle\Class\Schema\ClassDefinitionList;
use Pimcore\Bundle\StudioBackendBundle\Class\Service\ClassDefinitionServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
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\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
use Symfony\Component\Serializer\SerializerInterface;
use function count;

/**
* @internal
*/
final class ClassesController extends AbstractApiController
{
use PaginatedResponseTrait;

private const string ROUTE = '/class/object-brick/classes';

public function __construct(

Check notice on line 43 in src/Class/Controller/ObjectBrick/ClassesController.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/Class/Controller/ObjectBrick/ClassesController.php#L43

Expected 2 blank lines before function; 1 found
SerializerInterface $serializer,
private readonly ClassDefinitionServiceInterface $classDefinitionService,

Check notice on line 45 in src/Class/Controller/ObjectBrick/ClassesController.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/Class/Controller/ObjectBrick/ClassesController.php#L45

Avoid excessively long variable names like $classDefinitionService. Keep variable name length under 20.
) {
parent::__construct($serializer);
}

Check notice on line 48 in src/Class/Controller/ObjectBrick/ClassesController.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/Class/Controller/ObjectBrick/ClassesController.php#L48

Expected 1 blank line before closing function brace; 0 found

Check notice on line 48 in src/Class/Controller/ObjectBrick/ClassesController.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/Class/Controller/ObjectBrick/ClassesController.php#L48

Expected 2 blank lines after function; 1 found

#[Route(
self::ROUTE,
name: 'pimcore_studio_api_class_object_brick_classes',
methods: ['GET'],
priority: 10
)]
#[IsGranted(UserPermissions::OBJECT_BRICKS->value)]
#[Get(
path: self::PREFIX . self::ROUTE,
operationId: 'class_object_brick_classes',
description: 'class_object_brick_classes_description',
summary: 'class_object_brick_classes_summary',
tags: [Tags::ClassDefinition->value],
)]
#[SuccessResponse(
description: 'class_object_brick_classes_success_response',
content: new CollectionJson(new GenericCollection(ClassDefinitionList::class))
)]
#[DefaultResponses([
HttpResponseCodes::UNAUTHORIZED,
])]
public function getClassesWithObjectBricks(): JsonResponse
{
$items = $this->classDefinitionService->getClassDefinitionsWithObjectBricks();

return $this->getPaginatedCollection(
$this->serializer,
$items,
count($items)
);
}
}
Loading
Loading