Skip to content

Commit

Permalink
fix: correct initial_key_mapping and unique key
Browse files Browse the repository at this point in the history
  • Loading branch information
alexloetscher95 committed Jul 15, 2024
1 parent 1c4986e commit ea30b09
Showing 1 changed file with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function apply(Concrete $object, array $options): void
null !== $request &&
$this->matchesPimcoreContext($request, PimcoreContextResolver::CONTEXT_ADMIN) &&
$object->getKey() &&
$object->getId() === 0
!$object->getId()
) {
$setter = \sprintf('set%s', \ucfirst($options['initial_key_mapping']));

Expand All @@ -97,20 +97,20 @@ public function apply(Concrete $object, array $options): void
$key = $namingScheme;
}

$object->setKey($key);
$parentPath = $this->correctPath($parentPath);

if (!$options['skip_path_for_variant'] || $object->getType() !== AbstractObject::OBJECT_TYPE_VARIANT) {
$object->setParent(Service::createFolderByPath($parentPath));
}

if (!$object->getKey()) {
if (!$key) {
$className = \strtolower(\ltrim(\preg_replace(
'/[A-Z]([A-Z](?![a-z]))*/',
'_$0',
$object->getClassName()
), '_'));
$object->setKey(uniqid(\sprintf('%s_', $className), true));
$key = uniqid(\sprintf('%s_', $className), true);
}

$object->setKey($key);
$parentPath = $this->correctPath($parentPath);

if (!$options['skip_path_for_variant'] || $object->getType() !== AbstractObject::OBJECT_TYPE_VARIANT) {
$object->setParent(Service::createFolderByPath($parentPath));
}

$object->setKey(Service::getUniqueKey($object));
Expand Down

0 comments on commit ea30b09

Please sign in to comment.