Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Task] Add check for default metadata on patch #573

Merged
merged 3 commits into from
Nov 25, 2024
Merged
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
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,
];
}
}
Loading