-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/1.x' into change-doc-json-route
- Loading branch information
Showing
61 changed files
with
3,712 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
src/DataObject/Data/Adapter/AdvancedManyToManyObjectRelationAdapter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?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\StudioBackendBundle\DataObject\Data\Adapter; | ||
|
||
use Pimcore\Bundle\StaticResolverBundle\Models\DataObject\ConcreteObjectResolverInterface; | ||
use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\FieldContextData; | ||
use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\SetterDataInterface; | ||
use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterLoaderInterface; | ||
use Pimcore\Model\DataObject\ClassDefinition\Data; | ||
use Pimcore\Model\DataObject\ClassDefinition\Data\AdvancedManyToManyObjectRelation; | ||
use Pimcore\Model\DataObject\Concrete; | ||
use Pimcore\Model\DataObject\Data\ObjectMetadata; | ||
use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag; | ||
use function is_array; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
#[AutoconfigureTag(DataAdapterLoaderInterface::ADAPTER_TAG)] | ||
final readonly class AdvancedManyToManyObjectRelationAdapter implements SetterDataInterface | ||
{ | ||
public function __construct( | ||
private ConcreteObjectResolverInterface $concreteObjectResolver | ||
) { | ||
} | ||
|
||
public function getDataForSetter( | ||
Concrete $element, | ||
Data $fieldDefinition, | ||
string $key, | ||
array $data, | ||
?FieldContextData $contextData = null | ||
): ?array { | ||
|
||
$relationData = $data[$key]; | ||
if ($relationData === false || !is_array($relationData)) { | ||
return null; | ||
} | ||
|
||
return $this->buildRelationsMetadata($relationData, $fieldDefinition); | ||
} | ||
|
||
private function buildRelationsMetadata(array $relationData, Data $fieldDefinition): array | ||
{ | ||
if (!$fieldDefinition instanceof AdvancedManyToManyObjectRelation) { | ||
return []; | ||
} | ||
|
||
$relationsMetadata = []; | ||
foreach ($relationData as $relation) { | ||
$object = $this->concreteObjectResolver->getById($relation['id']); | ||
if ($object && $object->getClassName() === $fieldDefinition->getAllowedClassId()) { | ||
$relationsMetadata[] = $this->createObjectMetadata($object, $fieldDefinition, $relation); | ||
} | ||
} | ||
|
||
return $relationsMetadata; | ||
} | ||
|
||
private function createObjectMetadata( | ||
Concrete $object, | ||
AdvancedManyToManyObjectRelation $fieldDefinition, | ||
array $relation, | ||
): ObjectMetadata { | ||
$metaData = new ObjectMetadata( | ||
$fieldDefinition->getName(), | ||
$fieldDefinition->getColumnKeys(), | ||
$object | ||
); | ||
$metaData->_setOwner($object); | ||
$metaData->_setOwnerFieldname($fieldDefinition->getName()); | ||
|
||
foreach ($fieldDefinition->getColumns() as $column) { | ||
$setter = 'set' . ucfirst($column['key']); | ||
$value = $relation[$column['key']] ?? null; | ||
|
||
if ($column['type'] === 'multiselect' && is_array($value)) { | ||
$value = implode(',', $value); | ||
} | ||
|
||
$metaData->$setter($value); | ||
} | ||
|
||
return $metaData; | ||
} | ||
} |
Oops, something went wrong.