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
1 change: 1 addition & 0 deletions doc/05_Additional_Custom_Attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ final class AssetEvent extends AbstractPreResponseEvent
- `pre_response.custom_report_tree_node`
- `pre_response.custom_report.column_information`
- `pre_response.data_object`
- `pre_response.data_object_detail`
- `pre_response.data_object.dynamic_select_option`
- `pre_response.data_object.formated_path`
- `pre_response.data_object.layout`
Expand Down
7 changes: 4 additions & 3 deletions src/DataIndex/Adapter/DataObjectSearchAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
use Pimcore\Bundle\StudioBackendBundle\DataIndex\DataObjectSearchResult;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Query\QueryInterface;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Service\Hydrator\DataObjectHydratorServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Schema\DataObject;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Schema\DataObjectDetail;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Schema\Type\DataObjectFolder;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidSearchException;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\SearchException;
Expand Down Expand Up @@ -70,7 +71,7 @@ public function searchDataObjects(QueryInterface $dataObjectQuery): DataObjectSe
/**
* @throws SearchException|NotFoundException
*/
public function getDataObjectById(int $id, ?UserInterface $user = null): DataObject
public function getDataObjectById(int $id, ?UserInterface $user = null): DataObjectDetail|DataObjectFolder
{
try {
/** @var User $user
Expand All @@ -85,7 +86,7 @@ public function getDataObjectById(int $id, ?UserInterface $user = null): DataObj
throw new NotFoundException('DataObject', $id);
}

return $this->hydratorService->hydrateDataObjects($dataObject);
return $this->hydratorService->hydrateDetailObjects($dataObject);
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/DataIndex/Adapter/DataObjectSearchAdapterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Interfaces\ElementSearchResultItemInterface;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\DataObjectSearchResult;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Query\QueryInterface;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Schema\DataObject;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Schema\DataObjectDetail;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Schema\Type\DataObjectFolder;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidSearchException;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\SearchException;
Expand All @@ -32,7 +33,7 @@ public function searchDataObjects(QueryInterface $dataObjectQuery): DataObjectSe
/**
* @throws NotFoundException
*/
public function getDataObjectById(int $id, ?UserInterface $user = null): DataObject;
public function getDataObjectById(int $id, ?UserInterface $user = null): DataObjectDetail|DataObjectFolder;

/**
* @throws SearchException
Expand Down
1 change: 1 addition & 0 deletions src/DataIndex/Hydrator/DataObject/FolderHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function hydrate(Folder $item): DataObjectFolder
$item->getIndex(),
$item->getChildrenSortBy(),
$item->getChildrenSortOrder(),
null,
$item->getId(),
$item->getParentId(),
$item->getPath(),
Expand Down
27 changes: 25 additions & 2 deletions src/DataIndex/Hydrator/DataObjectHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,22 @@

use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\DataObject\SearchResult\DataObjectSearchResultItem;
use Pimcore\Bundle\GenericDataIndexBundle\SearchIndexAdapter\ElementLockServiceInterface;
use Pimcore\Bundle\StaticResolverBundle\Models\DataObject\ClassDefinitionResolverInterface;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Hydrator\DataObject\PermissionsHydratorInterface;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Schema\DataObject;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Schema\DataObjectDetail;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Util\Trait\ValidateObjectDataTrait;
use Pimcore\Bundle\StudioBackendBundle\Icon\Service\IconServiceInterface;

/**
* @internal
*/
final readonly class DataObjectHydrator implements DataObjectHydratorInterface
{
use ValidateObjectDataTrait;

public function __construct(
private ClassDefinitionResolverInterface $classDefinitionResolver,
private ElementLockServiceInterface $elementLockService,
private IconServiceInterface $iconService,
private PermissionsHydratorInterface $permissionsHydrator
Expand All @@ -34,6 +40,22 @@ public function __construct(
public function hydrate(DataObjectSearchResultItem $dataObject): DataObject
{
return new DataObject(
...$this->getObjectBaseData($dataObject)
);
}

public function hydrateDetail(DataObjectSearchResultItem $dataObject): DataObjectDetail
{
return new DataObjectDetail(
...$this->getObjectBaseData($dataObject)
);
}

private function getObjectBaseData(DataObjectSearchResultItem $dataObject): array
{
$class = $this->getValidClass($this->classDefinitionResolver, $dataObject->getClassId());

return [
$dataObject->getKey(),
$dataObject->getClassName(),
$dataObject->getType(),
Expand All @@ -45,6 +67,7 @@ public function hydrate(DataObjectSearchResultItem $dataObject): DataObject
$dataObject->getIndex(),
$dataObject->getChildrenSortBy(),
$dataObject->getChildrenSortOrder(),
$class->getAllowVariants(),
$dataObject->getId(),
$dataObject->getParentId(),
$dataObject->getPath(),
Expand All @@ -58,7 +81,7 @@ public function hydrate(DataObjectSearchResultItem $dataObject): DataObject
$dataObject->getLocked()
),
$dataObject->getCreationDate(),
$dataObject->getModificationDate()
);
$dataObject->getModificationDate(),
];
}
}
3 changes: 3 additions & 0 deletions src/DataIndex/Hydrator/DataObjectHydratorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@

use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\DataObject\SearchResult\DataObjectSearchResultItem;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Schema\DataObject;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Schema\DataObjectDetail;

/**
* @internal
*/
interface DataObjectHydratorInterface
{
public function hydrate(DataObjectSearchResultItem $dataObject): DataObject;

public function hydrateDetail(DataObjectSearchResultItem $dataObject): DataObjectDetail;
}
8 changes: 8 additions & 0 deletions src/DataIndex/Query/DataObjectQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\DataObject\DataObjectSearch;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\Basic\BooleanFilter;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\Basic\ExcludeFoldersFilter;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\Basic\ExcludeVariantsFilter;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\Basic\IdFilter;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\Basic\IdsFilter;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\Basic\IntegerFilter;
Expand Down Expand Up @@ -99,6 +100,13 @@ public function excludeFolders(): self
return $this;
}

public function excludeVariants(): self
{
$this->search->addModifier(new ExcludeVariantsFilter());

return $this;
}

/**
* @throws Exception
*/
Expand Down
2 changes: 2 additions & 0 deletions src/DataIndex/Query/DataObjectQueryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,6 @@ public function classificationStoreFilter(
WildcardSearch $subModifier,
?string $locale
): self;

public function excludeVariants(): self;
}
4 changes: 2 additions & 2 deletions src/DataIndex/Service/DataObjectSearchService.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use Pimcore\Bundle\StudioBackendBundle\DataIndex\DataObjectSearchResult;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Provider\DataObjectQueryProviderInterface;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Query\QueryInterface;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Schema\DataObject;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Schema\DataObjectDetail;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Schema\Type\DataObjectFolder;
use Pimcore\Bundle\StudioBackendBundle\Element\Util\Trait\SearchTermTrait;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidSearchException;
Expand All @@ -45,7 +45,7 @@ public function searchDataObjects(QueryInterface $dataObjectQuery): DataObjectSe
return $this->dataObjectSearchAdapter->searchDataObjects($dataObjectQuery);
}

public function getDataObjectById(int $id, ?UserInterface $user): DataObject|DataObjectFolder
public function getDataObjectById(int $id, ?UserInterface $user): DataObjectDetail|DataObjectFolder
{
return $this->dataObjectSearchAdapter->getDataObjectById($id, $user);
}
Expand Down
4 changes: 2 additions & 2 deletions src/DataIndex/Service/DataObjectSearchServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Interfaces\ElementSearchResultItemInterface;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\DataObjectSearchResult;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Query\QueryInterface;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Schema\DataObject;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Schema\DataObjectDetail;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Schema\Type\DataObjectFolder;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidSearchException;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException;
Expand All @@ -30,7 +30,7 @@ interface DataObjectSearchServiceInterface
{
public function searchDataObjects(QueryInterface $dataObjectQuery): DataObjectSearchResult;

public function getDataObjectById(int $id, ?UserInterface $user): DataObject|DataObjectFolder;
public function getDataObjectById(int $id, ?UserInterface $user): DataObjectDetail|DataObjectFolder;

/**
* @throws SearchException
Expand Down
11 changes: 11 additions & 0 deletions src/DataIndex/Service/Hydrator/DataObjectHydratorService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\DataObject\SearchResult\DataObjectSearchResultItem;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Hydrator\DataObjectHydratorInterface;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Schema\DataObject;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Schema\DataObjectDetail;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Schema\Type\DataObjectFolder;
use Symfony\Contracts\Service\ServiceProviderInterface;
use function get_class;
Expand All @@ -40,4 +41,14 @@ public function hydrateDataObjects(DataObjectSearchResultItem $item): DataObject

return $this->dataObjectHydrator->hydrate($item);
}

public function hydrateDetailObjects(DataObjectSearchResultItem $item): DataObjectDetail|DataObjectFolder
{
$class = get_class($item);
if ($this->hydratorLocator->has($class)) {
return $this->hydratorLocator->get($class)->hydrate($item);
}

return $this->dataObjectHydrator->hydrateDetail($item);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\DataObject\SearchResult\DataObjectSearchResultItem;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Schema\DataObject;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Schema\DataObjectDetail;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Schema\Type\DataObjectFolder;

/**
Expand All @@ -23,4 +24,6 @@
interface DataObjectHydratorServiceInterface
{
public function hydrateDataObjects(DataObjectSearchResultItem $item): DataObject|DataObjectFolder;

public function hydrateDetailObjects(DataObjectSearchResultItem $item): DataObjectDetail|DataObjectFolder;
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __construct()
items: new Items(
anyOf: array_map(static function ($class) {
return new Schema(ref: $class);
}, Schemas::DATA_OBJECTS)
}, Schemas::DATA_OBJECTS_COLLECTION)
)
);
}
Expand Down
48 changes: 48 additions & 0 deletions src/DataObject/Event/PreResponse/DataObjectDetailEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?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\DataObject\Event\PreResponse;

use Pimcore\Bundle\StudioBackendBundle\DataObject\Schema\DataObjectDetail;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Schema\Type\DataObjectFolder;
use Pimcore\Bundle\StudioBackendBundle\Element\Schema\CustomAttributes;
use Pimcore\Bundle\StudioBackendBundle\Event\AbstractPreResponseEvent;

final class DataObjectDetailEvent extends AbstractPreResponseEvent
{
public const string EVENT_NAME = 'pre_response.data_object_detail';

public function __construct(
private readonly DataObjectDetail|DataObjectFolder $dataObject
) {
parent::__construct($this->dataObject);
}

/**
* Use this to get additional info out of the response object
*/
public function getDataObject(): DataObjectDetail|DataObjectFolder
{
return $this->dataObject;
}

public function getCustomAttributes(): ?CustomAttributes
{
return $this->dataObject->getCustomAttributes();
}

public function setCustomAttributes(CustomAttributes $customAttributes): void
{
$this->dataObject->setCustomAttributes($customAttributes);
}
}
Loading
Loading