function move(FormControl $source, FormControl $target, $offset = 0)
{
// Remove the source control from its container's list of controls
$controls = array();
$source_name = false;
foreach ($source->container->controls as $name => $ctrl) {
if ($ctrl === $source) {
$source_name = $name;
continue;
}
$controls[$name] = $ctrl;
}
if ($source_name) {
$source->container->controls = $controls;
// Insert the source control into the destination control's container's list of controls in the correct location
$target_index = array_search($target, array_values($target->container->controls), true);
$left_slice = array_slice($target->container->controls, 0, $target_index + $offset, true);
$right_slice = array_slice($target->container->controls, $target_index + $offset, count($target->container->controls), true);
$target->container->controls = $left_slice + array($source_name => $source) + $right_slice;
}
}