/**
* Finds or create a new system-collection.
*
* @param string $key
* @param array $localizedTitles
* @param int $userId
* @param int|null $parent id of parent collection or null for root
*
* @return Collection
*/
private function getOrCreateCollection($key, $localizedTitles, $userId, $parent)
{
$locales = array_keys($localizedTitles);
$firstLocale = array_shift($locales);
$collection = $this->collectionManager->getByKey($key, $firstLocale);
if ($collection === null) {
$collection = $this->createCollection($localizedTitles[$firstLocale], $key, $firstLocale, $userId, $parent);
} else {
$collection->setTitle($localizedTitles[$firstLocale]);
}
foreach ($locales as $locale) {
$this->createCollection($localizedTitles[$locale], $key, $locale, $userId, $parent, $collection->getId());
}
return $collection;
}