Skip to content

Commit

Permalink
[Task] Add check for default metadata on patch (#573)
Browse files Browse the repository at this point in the history
* Add check for default metadata on patch

* Add space

* Apply php-cs-fixer changes

---------

Co-authored-by: mattamon <[email protected]>
  • Loading branch information
mattamon and mattamon authored Nov 25, 2024
1 parent 4dfa880 commit 09259fc
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 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 All @@ -25,6 +26,7 @@
use Pimcore\Model\Element\ElementInterface;
use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;
use function array_key_exists;
use function in_array;

/**
* @internal
Expand Down Expand Up @@ -109,6 +111,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 +141,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 09259fc

Please sign in to comment.