From 70236740cff93bbc51880e61696ce5a14ce129ea Mon Sep 17 00:00:00 2001 From: mattamon Date: Mon, 25 Nov 2024 16:07:24 +0100 Subject: [PATCH 1/3] Add check for default metadata on patch --- src/Asset/Patcher/Adapter/MetadataAdapter.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Asset/Patcher/Adapter/MetadataAdapter.php b/src/Asset/Patcher/Adapter/MetadataAdapter.php index 142743839..9699d8e9b 100644 --- a/src/Asset/Patcher/Adapter/MetadataAdapter.php +++ b/src/Asset/Patcher/Adapter/MetadataAdapter.php @@ -16,6 +16,7 @@ namespace Pimcore\Bundle\StudioBackendBundle\Asset\Patcher\Adapter; +use Pimcore\Bundle\StudioBackendBundle\Asset\Service\Data\CustomMetadataServiceInterface; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidArgumentException; use Pimcore\Bundle\StudioBackendBundle\Metadata\Repository\MetadataRepositoryInterface; use Pimcore\Bundle\StudioBackendBundle\Patcher\Service\Loader\PatchAdapterInterface; @@ -109,6 +110,10 @@ private function processNewMetadataEntry(array $metadata): array throw new InvalidArgumentException('Metadata name is required'); } + if(in_array($metadata['name'], CustomMetadataServiceInterface::DEFAULT_METADATA, true)) { + return $this->addDefaultMetadata($metadata); + } + $predefined = $this->metadataRepository->getPredefinedMetadataByName($metadata['name']); if (!$predefined) { @@ -135,4 +140,14 @@ private function findIndexOfMatch(array $metadata, array $patchMetadata): int|bo // Return the key of the first match return !empty($match) ? current($match) : false; } + + private function addDefaultMetadata(array $metadata): array + { + return [ + 'name' => $metadata['name'], + 'language' => $metadata['language'] ?? '', + 'type' => 'input', + 'data' => $metadata['data'] ?? null, + ]; + } } From 91e3b03187ffdb0d9fae3e2a9db54aeae88dc27b Mon Sep 17 00:00:00 2001 From: mattamon Date: Mon, 25 Nov 2024 16:09:19 +0100 Subject: [PATCH 2/3] Add space --- src/Asset/Patcher/Adapter/MetadataAdapter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Asset/Patcher/Adapter/MetadataAdapter.php b/src/Asset/Patcher/Adapter/MetadataAdapter.php index 9699d8e9b..66193d680 100644 --- a/src/Asset/Patcher/Adapter/MetadataAdapter.php +++ b/src/Asset/Patcher/Adapter/MetadataAdapter.php @@ -110,7 +110,7 @@ private function processNewMetadataEntry(array $metadata): array throw new InvalidArgumentException('Metadata name is required'); } - if(in_array($metadata['name'], CustomMetadataServiceInterface::DEFAULT_METADATA, true)) { + if (in_array($metadata['name'], CustomMetadataServiceInterface::DEFAULT_METADATA, true)) { return $this->addDefaultMetadata($metadata); } From 6f7de521d71dbda51aef1754f1109756edc996d0 Mon Sep 17 00:00:00 2001 From: mattamon Date: Mon, 25 Nov 2024 15:09:55 +0000 Subject: [PATCH 3/3] Apply php-cs-fixer changes --- src/Asset/Patcher/Adapter/MetadataAdapter.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Asset/Patcher/Adapter/MetadataAdapter.php b/src/Asset/Patcher/Adapter/MetadataAdapter.php index 66193d680..154f01db9 100644 --- a/src/Asset/Patcher/Adapter/MetadataAdapter.php +++ b/src/Asset/Patcher/Adapter/MetadataAdapter.php @@ -26,6 +26,7 @@ use Pimcore\Model\Element\ElementInterface; use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag; use function array_key_exists; +use function in_array; /** * @internal