public static function getValidKey($key, $type)
{
$results = \Pimcore::getEventManager()->trigger("system.service.preGetValidKey", null, ["key" => $key, "type" => $type]);
if ($results->count()) {
$key = $results->last();
}
$key = \Pimcore\Tool\Transliteration::toASCII($key);
if ($type == "document") {
// no spaces for documents / clean URLs
$key = preg_replace('/[^a-zA-Z0-9\\-\\.~_]+/', '-', $key);
} else {
// assets & objects including spaces
$key = preg_replace('/[^a-zA-Z0-9\\-\\.~_ ]+/', '-', $key);
}
if ($type == "asset") {
// keys shouldn't start with a "." (=hidden file) *nix operating systems
// keys shouldn't end with a "." - Windows issue: filesystem API trims automatically . at the end of a folder name (no warning ... et al)
$key = trim($key, ". ");
} else {
$key = trim($key);
$key = ltrim($key, ".");
}
return $key;
}