Skip to content

Commit

Permalink
Add check for default metadata on patch
Browse files Browse the repository at this point in the history
  • Loading branch information
mattamon committed Nov 25, 2024
1 parent 4dfa880 commit 7023674
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Asset/Patcher/Adapter/MetadataAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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,
];
}
}

0 comments on commit 7023674

Please sign in to comment.