diff --git a/config/classification_store.yaml b/config/classification_store.yaml index f71bed000..f7347663b 100644 --- a/config/classification_store.yaml +++ b/config/classification_store.yaml @@ -25,6 +25,9 @@ services: Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Service\KeyGroupRelationServiceInterface: class: Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Service\KeyGroupRelationService + Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Service\KeyGroupLayoutServiceInterface: + class: Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Service\KeyGroupLayoutService + Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Service\SearchHelperServiceInterface: class: Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Service\SearchHelperService @@ -57,4 +60,7 @@ services: class: Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Hydrator\GroupHydrator Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Hydrator\KeyGroupRelationHydratorInterface: - class: Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Hydrator\KeyGroupRelationHydrator \ No newline at end of file + class: Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Hydrator\KeyGroupRelationHydrator + + Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Hydrator\GroupLayoutHydratorInterface: + class: Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Hydrator\GroupLayoutHydrator \ No newline at end of file diff --git a/src/ClassificationStore/Controller/GetLayoutByCollectionController.php b/src/ClassificationStore/Controller/GetLayoutByCollectionController.php new file mode 100644 index 000000000..f2f48254b --- /dev/null +++ b/src/ClassificationStore/Controller/GetLayoutByCollectionController.php @@ -0,0 +1,105 @@ +value)] + #[Get( + path: self::PREFIX . '/classification-store/layout-by-collection/{collectionId}', + operationId: 'classification_store_get_layout_by_collection', + description: 'classification_store_get_layout_by_collection_description', + summary: 'classification_store_get_layout_by_collection_summary', + tags: [Tags::ClassificationStore->value] + )] + #[SuccessResponse( + description: 'classification_store_get_layout_by_collection_response', + content: new JsonContent(ref: CollectionLayout::class, type: 'object') + )] + #[QueryIdParameter( + description: 'object ID', + namePrefix: 'object', + required: false + )] + #[PathIdParameter( + type: 'Collection ID', + name: 'collectionId', + )] + #[TextFieldParameter( + name: 'fieldName', + description: 'Field Name', + required: true, + example: 'technicalAttributes' + )] + #[DefaultResponses([ + HttpResponseCodes::FORBIDDEN, + HttpResponseCodes::UNAUTHORIZED, + HttpResponseCodes::NOT_FOUND, + ])] + public function getLayoutByCollection( + #[MapQueryString] LayoutParameter $layoutParameter, + int $collectionId, + ): JsonResponse { + return $this->jsonResponse( + $this->collectionService->getLayoutDefinition($collectionId, $layoutParameter) + ); + } +} diff --git a/src/ClassificationStore/Controller/GetLayoutByGroupController.php b/src/ClassificationStore/Controller/GetLayoutByGroupController.php new file mode 100644 index 000000000..c9cbf94e3 --- /dev/null +++ b/src/ClassificationStore/Controller/GetLayoutByGroupController.php @@ -0,0 +1,105 @@ +value)] + #[Get( + path: self::PREFIX . '/classification-store/layout-by-group/{groupId}', + operationId: 'classification_store_get_layout_by_group', + description: 'classification_store_get_layout_by_group_description', + summary: 'classification_store_get_layout_by_group_summary', + tags: [Tags::ClassificationStore->value] + )] + #[SuccessResponse( + description: 'classification_store_get_layout_by_group_response', + content: new JsonContent(ref: GroupLayout::class, type: 'object') + )] + #[QueryIdParameter( + description: 'object ID', + namePrefix: 'object', + required: false + )] + #[PathIdParameter( + type: 'Group ID', + name: 'groupId', + )] + #[TextFieldParameter( + name: 'fieldName', + description: 'Field Name', + required: true, + example: 'technicalAttributes' + )] + #[DefaultResponses([ + HttpResponseCodes::FORBIDDEN, + HttpResponseCodes::UNAUTHORIZED, + HttpResponseCodes::NOT_FOUND, + ])] + public function getLayoutByGroup( + #[MapQueryString] LayoutParameter $layoutParameter, + int $groupId, + ): JsonResponse { + return $this->jsonResponse( + $this->groupService->getLayoutDefinition($groupId, $layoutParameter) + ); + } +} diff --git a/src/ClassificationStore/Event/CollectionEvent.php b/src/ClassificationStore/Event/CollectionEvent.php index dbc038ae5..cbaf091d1 100644 --- a/src/ClassificationStore/Event/CollectionEvent.php +++ b/src/ClassificationStore/Event/CollectionEvent.php @@ -19,9 +19,6 @@ use Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Schema\Collection; use Pimcore\Bundle\StudioBackendBundle\Event\AbstractPreResponseEvent; -/** - * @internal - */ final class CollectionEvent extends AbstractPreResponseEvent { public const EVENT_NAME = 'pre_response.classification_store.collection'; diff --git a/src/ClassificationStore/Event/GroupEvent.php b/src/ClassificationStore/Event/GroupEvent.php index 885862095..095647582 100644 --- a/src/ClassificationStore/Event/GroupEvent.php +++ b/src/ClassificationStore/Event/GroupEvent.php @@ -19,9 +19,6 @@ use Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Schema\Group; use Pimcore\Bundle\StudioBackendBundle\Event\AbstractPreResponseEvent; -/** - * @internal - */ final class GroupEvent extends AbstractPreResponseEvent { public const EVENT_NAME = 'pre_response.classification_store.group'; diff --git a/src/ClassificationStore/Event/GroupLayoutEvent.php b/src/ClassificationStore/Event/GroupLayoutEvent.php new file mode 100644 index 000000000..dd057bded --- /dev/null +++ b/src/ClassificationStore/Event/GroupLayoutEvent.php @@ -0,0 +1,39 @@ +groupLayout; + } +} diff --git a/src/ClassificationStore/Event/KeyGroupRelationEvent.php b/src/ClassificationStore/Event/KeyGroupRelationEvent.php index 20157c433..4d59a0c11 100644 --- a/src/ClassificationStore/Event/KeyGroupRelationEvent.php +++ b/src/ClassificationStore/Event/KeyGroupRelationEvent.php @@ -19,9 +19,6 @@ use Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Schema\KeyGroupRelation; use Pimcore\Bundle\StudioBackendBundle\Event\AbstractPreResponseEvent; -/** - * @internal - */ final class KeyGroupRelationEvent extends AbstractPreResponseEvent { public const EVENT_NAME = 'pre_response.classification_store.key_group_relation'; diff --git a/src/ClassificationStore/Hydrator/GroupLayoutHydrator.php b/src/ClassificationStore/Hydrator/GroupLayoutHydrator.php new file mode 100644 index 000000000..e749ea739 --- /dev/null +++ b/src/ClassificationStore/Hydrator/GroupLayoutHydrator.php @@ -0,0 +1,36 @@ +getId(), + name: $group->getName(), + description: $group->getDescription(), + keys: $keys, + ); + } +} diff --git a/src/ClassificationStore/Hydrator/GroupLayoutHydratorInterface.php b/src/ClassificationStore/Hydrator/GroupLayoutHydratorInterface.php new file mode 100644 index 000000000..af22c3817 --- /dev/null +++ b/src/ClassificationStore/Hydrator/GroupLayoutHydratorInterface.php @@ -0,0 +1,32 @@ + $keys + */ + public function hydrate(array $keys, GroupConfig $group): GroupLayout; +} diff --git a/src/ClassificationStore/MappedParameter/LayoutParameter.php b/src/ClassificationStore/MappedParameter/LayoutParameter.php new file mode 100644 index 000000000..40f950d5c --- /dev/null +++ b/src/ClassificationStore/MappedParameter/LayoutParameter.php @@ -0,0 +1,43 @@ +fieldName; + } + + public function getObjectId(): int + { + return $this->objectId; + } +} diff --git a/src/ClassificationStore/Repository/CollectionRelationsRepository.php b/src/ClassificationStore/Repository/CollectionRelationsRepository.php index 25a0046f1..72e575e7c 100644 --- a/src/ClassificationStore/Repository/CollectionRelationsRepository.php +++ b/src/ClassificationStore/Repository/CollectionRelationsRepository.php @@ -20,6 +20,7 @@ use Doctrine\DBAL\Exception; use Pimcore\Bundle\StaticResolverBundle\Db\DbResolverInterface; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\DatabaseException; +use Pimcore\Model\DataObject\Classificationstore\CollectionGroupRelation; /** * @internal @@ -58,4 +59,15 @@ public function getCollectionIdsWith(array $groupIds): array throw new DatabaseException($e->getMessage()); } } + + /** + * {@inheritDoc} + */ + public function getFromCollection(int $collectionId): array + { + $listing = new CollectionGroupRelation\Listing(); + $listing->setCondition('colId = ?', $collectionId); + + return $listing->load(); + } } diff --git a/src/ClassificationStore/Repository/CollectionRelationsRepositoryInterface.php b/src/ClassificationStore/Repository/CollectionRelationsRepositoryInterface.php index 4c6bc3e6c..832df02e5 100644 --- a/src/ClassificationStore/Repository/CollectionRelationsRepositoryInterface.php +++ b/src/ClassificationStore/Repository/CollectionRelationsRepositoryInterface.php @@ -17,6 +17,7 @@ namespace Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Repository; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\DatabaseException; +use Pimcore\Model\DataObject\Classificationstore\CollectionGroupRelation; /** * @internal @@ -31,4 +32,10 @@ interface CollectionRelationsRepositoryInterface * @throws DatabaseException */ public function getCollectionIdsWith(array $groupIds): array; + + /** + * @return array + * + */ + public function getFromCollection(int $collectionId): array; } diff --git a/src/ClassificationStore/Repository/GroupConfigRepository.php b/src/ClassificationStore/Repository/GroupConfigRepository.php index 997621343..987b9c18a 100644 --- a/src/ClassificationStore/Repository/GroupConfigRepository.php +++ b/src/ClassificationStore/Repository/GroupConfigRepository.php @@ -17,7 +17,9 @@ namespace Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Repository; use Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Service\SearchHelperServiceInterface; +use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException; use Pimcore\Bundle\StudioBackendBundle\MappedParameter\CollectionParametersInterface; +use Pimcore\Model\DataObject\Classificationstore\GroupConfig; use Pimcore\Model\DataObject\Classificationstore\GroupConfig\Listing; use function count; @@ -80,6 +82,20 @@ public function getCountByStoreId(int $storeId): int return $listing->count(); } + /** + * {@inheritDoc} + */ + public function getById(int $id): GroupConfig + { + $group = GroupConfig::getById($id); + + if (!$group) { + throw new NotFoundException('group', $id); + } + + return $group; + } + private function applyGroupIdsFilter(Listing $list, array $groupIds): void { $placeholders = implode(',', array_fill(0, count($groupIds), '?')); diff --git a/src/ClassificationStore/Repository/GroupConfigRepositoryInterface.php b/src/ClassificationStore/Repository/GroupConfigRepositoryInterface.php index ee3f009b2..b106115d1 100644 --- a/src/ClassificationStore/Repository/GroupConfigRepositoryInterface.php +++ b/src/ClassificationStore/Repository/GroupConfigRepositoryInterface.php @@ -16,6 +16,7 @@ namespace Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Repository; +use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException; use Pimcore\Bundle\StudioBackendBundle\MappedParameter\CollectionParametersInterface; use Pimcore\Model\DataObject\Classificationstore\GroupConfig; @@ -42,4 +43,9 @@ public function getAllGroupsByStore( ): array; public function getCountByStoreId(int $storeId): int; + + /** + * @throws NotFoundException + */ + public function getById(int $id): GroupConfig; } diff --git a/src/ClassificationStore/Repository/KeyGroupRelationRepository.php b/src/ClassificationStore/Repository/KeyGroupRelationRepository.php index 05fc1330d..6c6083328 100644 --- a/src/ClassificationStore/Repository/KeyGroupRelationRepository.php +++ b/src/ClassificationStore/Repository/KeyGroupRelationRepository.php @@ -75,6 +75,19 @@ public function getCountByStoreId(int $storeId, ?array $groupIds = null): int return $listing->count(); } + /** + * {@inheritdoc} + */ + public function getByGroupId(int $groupId): array + { + $listing = new Listing(); + $listing->setOrder('ASC'); + $listing->setOrderKey('id'); + $listing->setCondition('groupID = ?', [$groupId]); + + return $listing->load(); + } + private function applySearchTermFilter(Listing $list, string $searchTerm): void { $searchTerms = $this->searchHelperService->getTranslatedSearchFilterTerms($searchTerm); diff --git a/src/ClassificationStore/Repository/KeyGroupRelationRepositoryInterface.php b/src/ClassificationStore/Repository/KeyGroupRelationRepositoryInterface.php index 82aa0fea3..d09e70d4b 100644 --- a/src/ClassificationStore/Repository/KeyGroupRelationRepositoryInterface.php +++ b/src/ClassificationStore/Repository/KeyGroupRelationRepositoryInterface.php @@ -35,4 +35,9 @@ public function getPaginatedKeyGroupRelationByStore( ): array; public function getCountByStoreId(int $storeId, ?array $groupIds = null): int; + + /** + * @return KeyGroupRelation[] + */ + public function getByGroupId(int $groupId): array; } diff --git a/src/ClassificationStore/Schema/Collection.php b/src/ClassificationStore/Schema/Collection.php index 85efe4561..44fe5c88a 100644 --- a/src/ClassificationStore/Schema/Collection.php +++ b/src/ClassificationStore/Schema/Collection.php @@ -21,9 +21,6 @@ use Pimcore\Bundle\StudioBackendBundle\Util\Schema\AdditionalAttributesInterface; use Pimcore\Bundle\StudioBackendBundle\Util\Trait\AdditionalAttributesTrait; -/** - * @internal - */ #[Schema( title: 'Classification Store Collection', required: [ diff --git a/src/ClassificationStore/Schema/CollectionLayout.php b/src/ClassificationStore/Schema/CollectionLayout.php new file mode 100644 index 000000000..da3f9d72a --- /dev/null +++ b/src/ClassificationStore/Schema/CollectionLayout.php @@ -0,0 +1,46 @@ +groups; + } +} diff --git a/src/ClassificationStore/Schema/Group.php b/src/ClassificationStore/Schema/Group.php index c7a61bbf7..0d4590ae0 100644 --- a/src/ClassificationStore/Schema/Group.php +++ b/src/ClassificationStore/Schema/Group.php @@ -21,9 +21,6 @@ use Pimcore\Bundle\StudioBackendBundle\Util\Schema\AdditionalAttributesInterface; use Pimcore\Bundle\StudioBackendBundle\Util\Trait\AdditionalAttributesTrait; -/** - * @internal - */ #[Schema( title: 'Classification Store Group', required: [ diff --git a/src/ClassificationStore/Schema/GroupLayout.php b/src/ClassificationStore/Schema/GroupLayout.php new file mode 100644 index 000000000..cffbda298 --- /dev/null +++ b/src/ClassificationStore/Schema/GroupLayout.php @@ -0,0 +1,72 @@ +id; + } + + public function getName(): string + { + return $this->name; + } + + public function getDescription(): string + { + return $this->description; + } + + /** + * @return KeyLayout[] + */ + public function getKeys(): array + { + return $this->keys; + } +} diff --git a/src/ClassificationStore/Schema/KeyGroupRelation.php b/src/ClassificationStore/Schema/KeyGroupRelation.php index a1ecefbd1..8f55220a8 100644 --- a/src/ClassificationStore/Schema/KeyGroupRelation.php +++ b/src/ClassificationStore/Schema/KeyGroupRelation.php @@ -21,9 +21,6 @@ use Pimcore\Bundle\StudioBackendBundle\Util\Schema\AdditionalAttributesInterface; use Pimcore\Bundle\StudioBackendBundle\Util\Trait\AdditionalAttributesTrait; -/** - * @internal - */ #[Schema( title: 'Classification Store KeyGroupRelation', required: [ diff --git a/src/ClassificationStore/Schema/KeyLayout.php b/src/ClassificationStore/Schema/KeyLayout.php new file mode 100644 index 000000000..a5a85afe8 --- /dev/null +++ b/src/ClassificationStore/Schema/KeyLayout.php @@ -0,0 +1,70 @@ +id; + } + + public function getName(): string + { + return $this->name; + } + + public function getDescription(): string + { + return $this->description; + } + + public function getDefinition(): EncryptedField|Data + { + return $this->definition; + } +} diff --git a/src/ClassificationStore/Service/CollectionService.php b/src/ClassificationStore/Service/CollectionService.php index 2741a925e..8301205df 100644 --- a/src/ClassificationStore/Service/CollectionService.php +++ b/src/ClassificationStore/Service/CollectionService.php @@ -19,9 +19,11 @@ use Exception; use Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Event\CollectionEvent; use Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Hydrator\CollectionHydratorInterface; +use Pimcore\Bundle\StudioBackendBundle\ClassificationStore\MappedParameter\LayoutParameter; use Pimcore\Bundle\StudioBackendBundle\ClassificationStore\MappedParameter\ListClassificationStoreParameter; use Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Repository\CollectionConfigRepositoryInterface; use Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Repository\CollectionRelationsRepositoryInterface; +use Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Schema\CollectionLayout; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\DatabaseException; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException; use Pimcore\Bundle\StudioBackendBundle\Response\Collection; @@ -78,6 +80,23 @@ public function getCollections(ListClassificationStoreParameter $parameter): Col ); } + /** + * {@inheritDoc} + */ + public function getLayoutDefinition(int $collectionId, LayoutParameter $layoutParameter): CollectionLayout + { + $groups = $this->collectionRelationsRepository->getFromCollection($collectionId); + + $layouts = []; + foreach ($groups as $group) { + $layouts[] = $this->groupService->getLayoutDefinition($group->getGroupId(), $layoutParameter); + } + + return new CollectionLayout( + groups: $layouts + ); + } + /** * @return array * diff --git a/src/ClassificationStore/Service/CollectionServiceInterface.php b/src/ClassificationStore/Service/CollectionServiceInterface.php index d1aca9278..18b70c71d 100644 --- a/src/ClassificationStore/Service/CollectionServiceInterface.php +++ b/src/ClassificationStore/Service/CollectionServiceInterface.php @@ -17,7 +17,9 @@ namespace Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Service; use Exception; +use Pimcore\Bundle\StudioBackendBundle\ClassificationStore\MappedParameter\LayoutParameter; use Pimcore\Bundle\StudioBackendBundle\ClassificationStore\MappedParameter\ListClassificationStoreParameter; +use Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Schema\CollectionLayout; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException; use Pimcore\Bundle\StudioBackendBundle\Response\Collection; @@ -31,4 +33,10 @@ interface CollectionServiceInterface * @throws NotFoundException */ public function getCollections(ListClassificationStoreParameter $parameter): Collection; + + /** + * @throws Exception + * @throws NotFoundException + */ + public function getLayoutDefinition(int $collectionId, LayoutParameter $layoutParameter): CollectionLayout; } diff --git a/src/ClassificationStore/Service/GroupService.php b/src/ClassificationStore/Service/GroupService.php index ec94a0b10..bfc7ad4d2 100644 --- a/src/ClassificationStore/Service/GroupService.php +++ b/src/ClassificationStore/Service/GroupService.php @@ -18,9 +18,15 @@ use Pimcore\Bundle\StaticResolverBundle\Models\DataObject\ConcreteObjectResolver; use Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Event\GroupEvent; +use Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Event\GroupLayoutEvent; use Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Hydrator\GroupHydratorInterface; +use Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Hydrator\GroupLayoutHydratorInterface; +use Pimcore\Bundle\StudioBackendBundle\ClassificationStore\MappedParameter\LayoutParameter; use Pimcore\Bundle\StudioBackendBundle\ClassificationStore\MappedParameter\ListClassificationStoreParameter; use Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Repository\GroupConfigRepositoryInterface; +use Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Repository\KeyGroupRelationRepositoryInterface; +use Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Schema\GroupLayout; +use Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Schema\KeyLayout; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException; use Pimcore\Bundle\StudioBackendBundle\Response\Collection; use Pimcore\Model\DataObject\ClassDefinition\Data\Classificationstore; @@ -37,6 +43,9 @@ public function __construct( private GroupConfigRepositoryInterface $groupConfigRepository, private EventDispatcherInterface $eventDispatcher, private GroupHydratorInterface $groupHydrator, + private KeyGroupRelationRepositoryInterface $keyGroupRelationRepository, + private KeyGroupLayoutServiceInterface $keyGroupLayoutService, + private GroupLayoutHydratorInterface $groupLayoutHydrator, ) { } @@ -98,4 +107,43 @@ public function getAllowedGroupIds(ListClassificationStoreParameter $parameter): return $fieldDefinition->getAllowedGroupIds(); } + + /** + * {@inheritDoc} + */ + public function getLayoutDefinition(int $groupId, LayoutParameter $layoutParameter): GroupLayout + { + $keys = $this->keyGroupRelationRepository->getByGroupId($groupId); + $object = $this->concreteObjectResolver->getById($layoutParameter->getObjectId()); + + if (!$object) { + throw new NotFoundException('object', $layoutParameter->getObjectId()); + } + + $keyLayouts = []; + foreach ($keys as $key) { + $definition = $this->keyGroupLayoutService->getLayoutDefinition( + $key, + $object, + $layoutParameter->getFieldName() + ); + + $keyLayouts[] = new KeyLayout( + id: $key->getKeyId(), + name: $key->getName(), + description: $key->getDescription(), + definition: $definition, + ); + } + + $group = $this->groupConfigRepository->getById($groupId); + $groupLayout = $this->groupLayoutHydrator->hydrate($keyLayouts, $group); + + $this->eventDispatcher->dispatch( + new GroupLayoutEvent($groupLayout), + GroupLayoutEvent::EVENT_NAME + ); + + return $groupLayout; + } } diff --git a/src/ClassificationStore/Service/GroupServiceInterface.php b/src/ClassificationStore/Service/GroupServiceInterface.php index e71ade792..16ee2830b 100644 --- a/src/ClassificationStore/Service/GroupServiceInterface.php +++ b/src/ClassificationStore/Service/GroupServiceInterface.php @@ -17,7 +17,9 @@ namespace Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Service; use Exception; +use Pimcore\Bundle\StudioBackendBundle\ClassificationStore\MappedParameter\LayoutParameter; use Pimcore\Bundle\StudioBackendBundle\ClassificationStore\MappedParameter\ListClassificationStoreParameter; +use Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Schema\GroupLayout; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException; use Pimcore\Bundle\StudioBackendBundle\Response\Collection; @@ -39,4 +41,10 @@ public function getGroups(ListClassificationStoreParameter $parameter): Collecti * @throws NotFoundException */ public function getAllowedGroupIds(ListClassificationStoreParameter $parameter): array; + + /** + * @throws Exception + * @throws NotFoundException + */ + public function getLayoutDefinition(int $groupId, LayoutParameter $layoutParameter): GroupLayout; } diff --git a/src/ClassificationStore/Service/KeyGroupLayoutService.php b/src/ClassificationStore/Service/KeyGroupLayoutService.php new file mode 100644 index 000000000..3c16fb1d1 --- /dev/null +++ b/src/ClassificationStore/Service/KeyGroupLayoutService.php @@ -0,0 +1,68 @@ +getDefinition(), true); + $definition = $this->serviceResolver->getFieldDefinitionFromJson( + $definition, + $keyGroupRelation->getType() + ); + + if (method_exists($definition, '__wakeup')) { + $definition->__wakeup(); + } + + if ($definition instanceof LayoutDefinitionEnrichmentInterface) { + $context['object'] = $object; + $context['class'] = $object->getClass(); + $context['ownerType'] = 'classificationstore'; + $context['ownerName'] = $fieldName; + $context['keyId'] = $keyGroupRelation->getKeyId(); + $context['groupId'] = $keyGroupRelation->getGroupId(); + $context['keyDefinition'] = $definition; + + $definition = $definition->enrichLayoutDefinition($object, $context); + } + + return $definition; + } +} diff --git a/src/ClassificationStore/Service/KeyGroupLayoutServiceInterface.php b/src/ClassificationStore/Service/KeyGroupLayoutServiceInterface.php new file mode 100644 index 000000000..6a539c70a --- /dev/null +++ b/src/ClassificationStore/Service/KeyGroupLayoutServiceInterface.php @@ -0,0 +1,38 @@ +getDefinition(), true); + $definition = \Pimcore\Model\DataObject\Classificationstore\Service::getFieldDefinitionFromJson( + $definition, + $keyGroupRelation->getType() + ); + + if (method_exists($definition, '__wakeup')) { + $definition->__wakeup(); + } + + if ($definition instanceof LayoutDefinitionEnrichmentInterface) { + $context['object'] = $object; + $context['class'] = $object->getClass(); + $context['ownerType'] = 'classificationstore'; + $context['ownerName'] = $fieldName; + $context['keyId'] = $keyGroupRelation->getKeyId(); + $context['groupId'] = $keyGroupRelation->getGroupId(); + $context['keyDefinition'] = $definition; + + $definition = $definition->enrichLayoutDefinition($object, $context); + } + + return $definition; + } } diff --git a/translations/studio_api_docs.en.yaml b/translations/studio_api_docs.en.yaml index 0bf5e9443..983f76ea5 100644 --- a/translations/studio_api_docs.en.yaml +++ b/translations/studio_api_docs.en.yaml @@ -897,4 +897,10 @@ classification_store_get_groups_summary: Get all classification store groups for classification_store_get_groups_response: List of classification store groups classification_store_get_key_group_relations_description: Get all classification store key group relations for given fieldName classification_store_get_key_group_relations_summary: Get all classification store key group relations for given fieldName -classification_store_get_key_group_relations_response: List of classification store key group relations \ No newline at end of file +classification_store_get_key_group_relations_response: List of classification store key group relations +classification_store_get_layout_by_group_description: Get Layout definition for given group +classification_store_get_layout_by_group_summary: Get Layout definition for given group +classification_store_get_layout_by_group_response: Layout definition +classification_store_get_layout_by_collection_description: Get Layout definition for given collection +classification_store_get_layout_by_collection_summary: Get Layout definition for given collection +classification_store_get_layout_by_collection_response: Layout definition \ No newline at end of file