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 src/Enum/SearchIndex/FieldCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ enum FieldCategory: string
case SYSTEM_FIELDS = 'system_fields';
case STANDARD_FIELDS = 'standard_fields';
case CUSTOM_FIELDS = 'custom_fields';
case INHERITED_FIELDS = '_inherited_fields';
}
29 changes: 29 additions & 0 deletions src/Enum/SearchIndex/FieldCategory/StandardField.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
declare(strict_types=1);

/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\GenericDataIndexBundle\Enum\SearchIndex\FieldCategory;

use Pimcore\Bundle\GenericDataIndexBundle\Enum\SearchIndex\FieldCategory\SystemField\SystemFieldTrait;

/**
* @internal
*/
enum StandardField: string
{
use SystemFieldTrait;

case LOCALIZED_FIELDS = 'localizedfields';
}
4 changes: 2 additions & 2 deletions src/Enum/SearchIndex/FieldCategory/SystemField.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@

namespace Pimcore\Bundle\GenericDataIndexBundle\Enum\SearchIndex\FieldCategory;

use Pimcore\Bundle\GenericDataIndexBundle\Enum\SearchIndex\FieldCategory;
use Pimcore\Bundle\GenericDataIndexBundle\Enum\SearchIndex\FieldCategory\SystemField\SystemFieldTrait;

/**
* @internal
*/
enum SystemField: string
{
use FieldCategory\SystemField\SystemFieldTrait;
use SystemFieldTrait;

case ID = 'id';
case ELEMENT_TYPE = 'elementType';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
namespace Pimcore\Bundle\GenericDataIndexBundle\Model\Search\DataObject\SearchResult;

use Pimcore\Bundle\GenericDataIndexBundle\Enum\SearchIndex\ElementType;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\DataObject\SearchResult\SearchResultItem\InheritedData;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Interfaces\ElementSearchResultItemInterface;
use Pimcore\Bundle\GenericDataIndexBundle\Permission\DataObjectPermissions;
use Pimcore\Bundle\GenericDataIndexBundle\Service\Search\SearchResultItem\LazyLoading\DataObjectLazyLoadingHandlerInterface;
Expand Down Expand Up @@ -63,6 +64,8 @@ class DataObjectSearchResultItem implements ElementSearchResultItemInterface

private DataObjectPermissions $permissions;

private array $inheritedFields = [];

private DataObjectLazyLoadingHandlerInterface $lazyLoadingHandler;

public function getElementType(): ElementType
Expand Down Expand Up @@ -322,6 +325,24 @@ public function setPermissions(DataObjectPermissions $permissions): DataObjectSe
return $this;
}

/**
* @return InheritedData[]
*/
public function getInheritedFields(): array
{
return $this->inheritedFields;
}

/**
* @param InheritedData[] $inheritedFields
*/
public function setInheritedFields(array $inheritedFields): DataObjectSearchResultItem
{
$this->inheritedFields = $inheritedFields;

return $this;
}

public function withLazyLoadingHandler(
?DataObjectLazyLoadingHandlerInterface $lazyLoadingHandler
): DataObjectSearchResultItem {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
declare(strict_types=1);

/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\GenericDataIndexBundle\Model\Search\DataObject\SearchResult\SearchResultItem;

final readonly class InheritedData
{
public function __construct(
private string $key,
private int $originId
) {

}

public function getKey(): string
{
return $this->key;
}

public function getOriginId(): int
{
return $this->originId;
}
}
14 changes: 14 additions & 0 deletions src/SearchIndexAdapter/DataObject/AdapterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

namespace Pimcore\Bundle\GenericDataIndexBundle\SearchIndexAdapter\DataObject;

use Exception;
use Pimcore\Model\DataObject\ClassDefinition\Data;
use Pimcore\Model\DataObject\Concrete;

/**
* @internal
Expand All @@ -35,4 +37,16 @@ public function getIndexAttributeName(): string;
* Used to normalize the data for the search index
*/
public function normalize(mixed $value): mixed;

/**
* @throws Exception
*/
public function getInheritedData(
Concrete $dataObject,
int $objectId,
mixed $value,
string $key,
?string $language = null,
callable $callback = null
): array;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@

namespace Pimcore\Bundle\GenericDataIndexBundle\SearchIndexAdapter\DataObject;

use Exception;
use Pimcore\Model\DataObject\ClassDefinition;
use Pimcore\Model\DataObject\ClassDefinition\Data;
use Pimcore\Model\DataObject\Concrete;

/**
* @internal
Expand All @@ -26,4 +29,14 @@ interface FieldDefinitionServiceInterface
public function getFieldDefinitionAdapter(ClassDefinition\Data $fieldDefinition): ?AdapterInterface;

public function normalizeValue(?ClassDefinition\Data $fieldDefinition, mixed $value): mixed;

/**
* @throws Exception
*/
public function getInheritedFieldData(
?Data $fieldDefinition,
Concrete $dataObject,
string $key,
mixed $value
): array;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@

namespace Pimcore\Bundle\GenericDataIndexBundle\SearchIndexAdapter\OpenSearch\DataObject\FieldDefinitionAdapter;

use Exception;
use Pimcore\Bundle\GenericDataIndexBundle\SearchIndexAdapter\DataObject\AdapterInterface;
use Pimcore\Bundle\GenericDataIndexBundle\SearchIndexAdapter\DataObject\FieldDefinitionServiceInterface;
use Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\SearchIndexConfigServiceInterface;
use Pimcore\Model\DataObject\ClassDefinition\Data;
use Pimcore\Model\DataObject\Concrete;
use Pimcore\Normalizer\NormalizerInterface;

abstract class AbstractAdapter implements AdapterInterface
Expand Down Expand Up @@ -64,4 +66,37 @@ public function normalize(mixed $value): mixed

return $value;
}

/**
* @throws Exception
*/
public function getInheritedData(
Concrete $dataObject,
int $objectId,
mixed $value,
string $key,
?string $language = null,
callable $callback = null
): array {
if (!$this->fieldDefinition->isEmpty($value)) {
return [];
}

$path = $key;
if ($language !== null) {
$path .= '.' . $language;
}

$parent = $dataObject->getNextParentForInheritance();
if ($parent === null) {
return $objectId === $dataObject->getId() ? [] : [$path => ['originId' => $dataObject->getId()]];
}

$parentValue = $callback ? $callback($parent, $key, $language) : $parent->get($key, $language);
if (!$this->fieldDefinition->isEmpty($parentValue)) {
return [$path => ['originId' => $parent->getId()]];
}

return $this->getInheritedData($parent, $objectId, $value, $key, $language, $callback);
}
}
Loading
Loading