#[Route(path: '/api/_action/clone/{entity}/{id}', name: 'api.clone', methods: ['POST'], requirements: ['version' => '\d+', 'entity' => '[a-zA-Z-]+', 'id' => '[0-9a-f]{32}'])]
public function clone(Context
$context, string
$entity, string
$id, Request
$request): JsonResponse
{ $behavior =
new CloneBehavior( $request->request->
all('overwrites'
),
$request->request->
getBoolean('cloneChildren', true
) );
$entity =
$this->
urlToSnakeCase($entity);
$definition =
$this->definitionRegistry->
getByEntityName($entity);
$missing =
$this->
validateAclPermissions($context,
$definition, AclRoleDefinition::PRIVILEGE_CREATE
);
if ($missing) { throw ApiException::
missingPrivileges([$missing]);
} /** @var EntityWrittenContainerEvent $eventContainer */
$eventContainer =
$context->
scope(Context::CRUD_API_SCOPE,
function DContext
$context) use ($definition,
$id,
$behavior): EntityWrittenContainerEvent
{ $entityRepo =
$this->definitionRegistry->
getRepository($definition->
getEntityName());
return $entityRepo->
clone($id,
$context, null,
$behavior);
});