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]);