Skip to content

Commit

Permalink
[Tags][Notes] Data objects API problem (#445)
Browse files Browse the repository at this point in the history
* use correct type for data objects

* Apply php-cs-fixer changes

* fix batch assignment

---------

Co-authored-by: lukmzig <[email protected]>
  • Loading branch information
lukmzig and lukmzig authored Sep 27, 2024
1 parent b41c33a commit d5864bd
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
19 changes: 19 additions & 0 deletions src/Note/MappedParameter/NoteElementParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

namespace Pimcore\Bundle\StudioBackendBundle\Note\MappedParameter;

use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidElementTypeException;
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\ElementTypes;
use function in_array;

/**
* @internal
*/
Expand All @@ -26,15 +30,30 @@ public function __construct(
private ?int $id = null,

) {
$this->validate();
}

public function getType(): ?string
{
if ($this->type === ElementTypes::TYPE_DATA_OBJECT) {
return ElementTypes::TYPE_OBJECT;
}

return $this->type;
}

public function getId(): ?int
{
return $this->id;
}

/**
* @throws InvalidElementTypeException
*/
private function validate(): void
{
if (!in_array($this->type, ElementTypes::ALLOWED_TYPES, true)) {
throw new InvalidElementTypeException($this->type);
}
}
}
3 changes: 2 additions & 1 deletion src/Tag/Controller/Element/BatchAssignController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\ElementSavingFailedException;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException;
use Pimcore\Bundle\StudioBackendBundle\MappedParameter\ElementTypeParameter as MappedElementTypeParameter;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Path\ElementTypeParameter;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\DefaultResponses;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags;
Expand Down Expand Up @@ -74,7 +75,7 @@ public function assignTag(
): JsonResponse {
$this->tagService->batchAssignTagsToElements(
new BatchCollectionParameters(
$elementType,
(new MappedElementTypeParameter($elementType))->getType(),
$elementTagCollection->getElementIds(),
$elementTagCollection->getTagsIds()
)
Expand Down
3 changes: 2 additions & 1 deletion src/Tag/Controller/Element/BatchReplaceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\ElementSavingFailedException;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException;
use Pimcore\Bundle\StudioBackendBundle\MappedParameter\ElementTypeParameter as MappedElementTypeParameter;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Path\ElementTypeParameter;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\DefaultResponses;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags;
Expand Down Expand Up @@ -74,7 +75,7 @@ public function assignTag(
): JsonResponse {
$this->tagService->batchReplaceTagsToElements(
new BatchCollectionParameters(
$elementType,
(new MappedElementTypeParameter($elementType))->getType(),
$elementTagCollection->getElementIds(),
$elementTagCollection->getTagsIds()
)
Expand Down
19 changes: 19 additions & 0 deletions src/Tag/MappedParameter/ElementParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

namespace Pimcore\Bundle\StudioBackendBundle\Tag\MappedParameter;

use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidElementTypeException;
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\ElementTypes;
use function in_array;

/**
* @internal
*/
Expand All @@ -25,15 +29,30 @@ public function __construct(
private ?string $type = null,
private ?int $id = null
) {
$this->validate();
}

public function getType(): ?string
{
if ($this->type === ElementTypes::TYPE_DATA_OBJECT) {
return ElementTypes::TYPE_OBJECT;
}

return $this->type;
}

public function getId(): ?int
{
return $this->id;
}

/**
* @throws InvalidElementTypeException
*/
private function validate(): void
{
if (!in_array($this->type, ElementTypes::ALLOWED_TYPES, true)) {
throw new InvalidElementTypeException($this->type);
}
}
}

0 comments on commit d5864bd

Please sign in to comment.