Skip to content

Commit

Permalink
adapt response of version detail endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
lukmzig committed Jan 20, 2025
1 parent 19e4cf3 commit 6eeb5a3
Show file tree
Hide file tree
Showing 21 changed files with 249 additions and 119 deletions.
4 changes: 2 additions & 2 deletions src/DataObject/Data/Adapter/BlockAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterLoaderInterface;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Util\Trait\ValidateFieldTypeTrait;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Util\Trait\ValidateObjectDataTrait;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidDataTypeException;
use Pimcore\Model\DataObject\ClassDefinition\Data;
use Pimcore\Model\DataObject\ClassDefinition\Data\Block;
Expand All @@ -39,7 +39,7 @@
#[AutoconfigureTag(DataAdapterLoaderInterface::ADAPTER_TAG)]
final readonly class BlockAdapter implements SetterDataInterface, DataNormalizerInterface
{
use ValidateFieldTypeTrait;
use ValidateObjectDataTrait;

public function __construct(
private DataAdapterServiceInterface $dataAdapterService,
Expand Down
4 changes: 2 additions & 2 deletions src/DataObject/Data/Adapter/ClassificationStoreAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterLoaderInterface;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Util\Trait\ValidateFieldTypeTrait;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Util\Trait\ValidateObjectDataTrait;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\DatabaseException;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException;
use Pimcore\Model\DataObject\ClassDefinition\Data;
Expand All @@ -54,7 +54,7 @@
DataNormalizerInterface,
DataInheritanceInterface
{
use ValidateFieldTypeTrait;
use ValidateObjectDataTrait;

public function __construct(
private DefinitionCacheResolverInterface $definitionCacheResolver,
Expand Down
4 changes: 2 additions & 2 deletions src/DataObject/Data/Adapter/FieldCollectionsAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterLoaderInterface;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Util\Trait\ValidateFieldTypeTrait;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Util\Trait\ValidateObjectDataTrait;
use Pimcore\Model\DataObject\ClassDefinition\Data;
use Pimcore\Model\DataObject\ClassDefinition\Data\Fieldcollections;
use Pimcore\Model\DataObject\Concrete;
Expand All @@ -39,7 +39,7 @@
#[AutoconfigureTag(DataAdapterLoaderInterface::ADAPTER_TAG)]
final readonly class FieldCollectionsAdapter implements SetterDataInterface, DataNormalizerInterface
{
use ValidateFieldTypeTrait;
use ValidateObjectDataTrait;

private const TYPE_KEY = 'type';

Expand Down
4 changes: 2 additions & 2 deletions src/DataObject/Data/Adapter/LocalizedFieldsAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\InheritanceServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Util\Trait\ValidateFieldTypeTrait;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Util\Trait\ValidateObjectDataTrait;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\DatabaseException;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidArgumentException;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException;
Expand All @@ -51,7 +51,7 @@
DataNormalizerInterface,
DataInheritanceInterface
{
use ValidateFieldTypeTrait;
use ValidateObjectDataTrait;

public function __construct(
private DataAdapterServiceInterface $dataAdapterService,
Expand Down
4 changes: 2 additions & 2 deletions src/DataObject/Data/Adapter/ObjectBricksAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\InheritanceServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Util\Trait\ValidateFieldTypeTrait;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Util\Trait\ValidateObjectDataTrait;
use Pimcore\Model\DataObject\ClassDefinition\Data;
use Pimcore\Model\DataObject\ClassDefinition\Data\Objectbricks;
use Pimcore\Model\DataObject\Concrete;
Expand All @@ -45,7 +45,7 @@
DataNormalizerInterface,
DataInheritanceInterface
{
use ValidateFieldTypeTrait;
use ValidateObjectDataTrait;

public function __construct(
private DataAdapterServiceInterface $dataAdapterService,
Expand Down
33 changes: 10 additions & 23 deletions src/DataObject/Service/DataObjectService.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use Pimcore\Bundle\StudioBackendBundle\DataObject\Schema\DataObject;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Schema\DataObjectAddParameters;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Schema\Type\DataObjectFolder;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Util\Trait\ValidateObjectDataTrait;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\AccessDeniedException;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\DatabaseException;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\ElementSavingFailedException;
Expand Down Expand Up @@ -64,13 +65,14 @@
{
use ElementProviderTrait;
use UserPermissionTrait;
use ValidateObjectDataTrait;

private const ALLOWED_TYPES = [
private const array ALLOWED_TYPES = [
AbstractObject::OBJECT_TYPE_OBJECT,
AbstractObject::OBJECT_TYPE_VARIANT,
];

private const INDEX_SORT = 'index';
private const string INDEX_SORT = 'index';

public function __construct(
private ClassDefinitionResolverInterface $classDefinitionResolver,
Expand Down Expand Up @@ -103,7 +105,7 @@ public function addDataObject(
throw new ElementSavingFailedException(null, 'Element with the same key and path already exists');
}

$class = $this->getValidClass($parameters->getClassId());
$class = $this->getValidClass($this->classDefinitionResolver, $parameters->getClassId());
$object = $this->getValidObjectByClass($parameters->getType(), $class->getName());

return $this->createNewObject(
Expand Down Expand Up @@ -255,24 +257,6 @@ private function getValidParent(UserInterface $user, int $parentId): DataObjectM
return $parent;
}

/**
* @throws DatabaseException|NotFoundException
*/
private function getValidClass(string $classId): ClassDefinition
{
try {
$class = $this->classDefinitionResolver->getById($classId);
} catch (Exception $exception) {
throw new DatabaseException($exception->getMessage());
}

if (!$class) {
throw new NotFoundException(ElementTypes::TYPE_CLASS_DEFINITION, $classId);
}

return $class;
}

/**
* @throws DatabaseException|InvalidElementTypeException
*/
Expand Down Expand Up @@ -347,11 +331,14 @@ private function getObjectDetailData(DataObjectFolder|DataObject $dataObject): v
{
$element = $this->getElement($this->serviceResolver, ElementTypes::TYPE_OBJECT, $dataObject->getId());
$element = $this->getLatestVersionForUser($element, $this->securityService->getCurrentUser());
if (!$element instanceof Concrete) {
if (!$element instanceof DataObjectModel) {
return;
}

$this->dataService->setObjectDetailData($dataObject, $element, $this->getValidClass($element->getClassId()));
$this->dataService->setObjectDetailData(
$dataObject,
$element
);
}

private function dispatchDataObjectEvent(mixed $dataObject): void
Expand Down
23 changes: 15 additions & 8 deletions src/DataObject/Service/DataService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@

namespace Pimcore\Bundle\StudioBackendBundle\DataObject\Service;

use Pimcore\Bundle\StaticResolverBundle\Models\DataObject\ClassDefinitionResolverInterface;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\DataNormalizerInterface;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Model\ClassData;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Schema\DataObject;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Schema\Type\DataObjectFolder;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Util\Trait\ValidateFieldTypeTrait;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Util\Trait\ValidateObjectDataTrait;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\DatabaseException;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException;
use Pimcore\Bundle\StudioBackendBundle\Version\Schema\DataObjectVersion;
use Pimcore\Bundle\StudioBackendBundle\Workflow\Service\WorkflowDetailsServiceInterface;
use Pimcore\Model\DataObject as DataObjectModel;
use Pimcore\Model\DataObject\ClassDefinition;
use Pimcore\Model\DataObject\ClassDefinition\Data;
use Pimcore\Model\DataObject\Concrete;
Expand All @@ -34,9 +37,10 @@
*/
final readonly class DataService implements DataServiceInterface
{
use ValidateFieldTypeTrait;
use ValidateObjectDataTrait;

public function __construct(
private ClassDefinitionResolverInterface $classDefinitionResolver,
private DataAdapterServiceInterface $dataAdapterService,
private InheritanceServiceInterface $inheritanceService,
private WorkflowDetailsServiceInterface $workflowDetailsService,
Expand All @@ -47,10 +51,15 @@ public function __construct(
* @throws DatabaseException|NotFoundException
*/
public function setObjectDetailData(
DataObjectFolder|DataObject $dataObject,
Concrete $element,
ClassDefinition $class
DataObjectFolder|DataObject|DataObjectVersion $dataObject,
DataObjectModel $element
): void {
$dataObject->setHasWorkflowAvailable($this->workflowDetailsService->hasElementWorkflows($element));
if ($dataObject instanceof DataObjectFolder || !$element instanceof Concrete) {
return;
}

$class = $this->getValidClass($this->classDefinitionResolver, $element->getClassId());
$classData = $this->getObjectClassData($class);
$fieldDefinitions = $class->getFieldDefinitions();

Expand All @@ -60,13 +69,11 @@ public function setObjectDetailData(
$dataObject->setHasPreview($classData->getHasPreview());
$dataObject->setObjectData($this->getNormalizedObjectData($element, $fieldDefinitions));

if ($dataObject->getAllowInheritance()) {
if ($dataObject instanceof DataObject && $dataObject->getAllowInheritance()) {
$dataObject->setInheritanceData(
$this->inheritanceService->getInheritanceData($element, $fieldDefinitions)
);
}

$dataObject->setHasWorkflowAvailable($this->workflowDetailsService->hasElementWorkflows($element));
}

public function getNormalizedValue(
Expand Down
9 changes: 4 additions & 5 deletions src/DataObject/Service/DataServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
use Pimcore\Bundle\StudioBackendBundle\DataObject\Schema\Type\DataObjectFolder;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\DatabaseException;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException;
use Pimcore\Model\DataObject\ClassDefinition;
use Pimcore\Bundle\StudioBackendBundle\Version\Schema\DataObjectVersion;
use Pimcore\Model\DataObject as DataObjectModel;
use Pimcore\Model\DataObject\ClassDefinition\Data;
use Pimcore\Model\DataObject\Concrete;

/**
* @internal
Expand All @@ -33,9 +33,8 @@ interface DataServiceInterface
* @throws DatabaseException|NotFoundException
*/
public function setObjectDetailData(
DataObjectFolder|DataObject $dataObject,
Concrete $element,
ClassDefinition $class
DataObjectFolder|DataObject|DataObjectVersion $dataObject,
DataObjectModel $element
): void;

public function getNormalizedValue(
Expand Down
4 changes: 2 additions & 2 deletions src/DataObject/Service/InheritanceService.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\DataInheritanceInterface;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Model\FieldContextData;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Model\InheritanceData;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Util\Trait\ValidateFieldTypeTrait;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Util\Trait\ValidateObjectDataTrait;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException;
use Pimcore\Model\DataObject\ClassDefinition\Data;
use Pimcore\Model\DataObject\Concrete;
Expand All @@ -31,7 +31,7 @@
*/
final readonly class InheritanceService implements InheritanceServiceInterface
{
use ValidateFieldTypeTrait;
use ValidateObjectDataTrait;

public function __construct(
private DataAdapterServiceInterface $dataAdapterService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
namespace Pimcore\Bundle\StudioBackendBundle\DataObject\Util\Trait;

use Exception;
use Pimcore\Bundle\StaticResolverBundle\Models\DataObject\ClassDefinitionResolverInterface;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\DatabaseException;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException;
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\ElementTypes;
use Pimcore\Model\DataObject\ClassDefinition;
use Pimcore\Model\DataObject\ClassDefinition\Data;
use Pimcore\Model\DataObject\ClassDefinition\Data\EncryptedField as EncryptedFieldDefinition;
use Pimcore\Model\DataObject\Concrete;
Expand All @@ -26,7 +30,7 @@
/**
* @internal
*/
trait ValidateFieldTypeTrait
trait ValidateObjectDataTrait
{
private function validateEncryptedField(Data $fieldDefinition, mixed $value): bool
{
Expand All @@ -47,4 +51,25 @@ private function getValidFieldValue(
throw new NotFoundException(type: 'field', id: $key);
}
}


/**
* @throws DatabaseException|NotFoundException
*/
private function getValidClass(
ClassDefinitionResolverInterface $classDefinitionResolver,
string $classId): ClassDefinition
{
try {
$class = $classDefinitionResolver->getById($classId);
} catch (Exception $exception) {
throw new DatabaseException($exception->getMessage());
}

if (!$class) {
throw new NotFoundException(ElementTypes::TYPE_CLASS_DEFINITION, $classId);
}

return $class;
}
}
Loading

0 comments on commit 6eeb5a3

Please sign in to comment.