From 4340989cba5c1513d32f25647a39cd8b6c586637 Mon Sep 17 00:00:00 2001 From: Aaron Gerig Date: Mon, 11 May 2020 15:56:04 +0200 Subject: [PATCH] feat: introduce initial key mapping when creating objects in the Pimcore backend --- .../NamingScheme/ExpressionNamingScheme.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/ElementManagerBundle/SaveManager/NamingScheme/ExpressionNamingScheme.php b/src/ElementManagerBundle/SaveManager/NamingScheme/ExpressionNamingScheme.php index 09e161d..26d112a 100644 --- a/src/ElementManagerBundle/SaveManager/NamingScheme/ExpressionNamingScheme.php +++ b/src/ElementManagerBundle/SaveManager/NamingScheme/ExpressionNamingScheme.php @@ -46,6 +46,7 @@ public function apply(Concrete $object, array $options): void 'scheme' => '', 'auto_prefix_path' => true, 'skip_path_for_variant' => false, + 'initial_key_mapping' => null, ]); $optionsResolver->setRequired([ 'parent_path', 'archive_path', 'scheme', 'auto_prefix_path' @@ -61,6 +62,15 @@ public function apply(Concrete $object, array $options): void array_merge($options, ['object' => $object, 'path' => $parentPath]) ); + // Map initial key to an object field + if ($options['initial_key_mapping'] && $object->getKey()) { + $setter = sprintf('set%s', ucfirst($options['initial_key_mapping'])); + + if (method_exists($object, $setter)) { + $object->$setter($object->getKey()); + } + } + if (is_array($namingScheme)) { $key = $namingScheme[count($namingScheme) - 1]; unset($namingScheme[count($namingScheme) - 1]);