Skip to content

Commit

Permalink
feat: introduce initial key mapping when creating objects in the Pimc…
Browse files Browse the repository at this point in the history
…ore backend
  • Loading branch information
Aaron Gerig committed May 11, 2020
1 parent 84d25ad commit 4340989
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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]);
Expand Down

0 comments on commit 4340989

Please sign in to comment.