Sulu\Bundle\MediaBundle\Collection\Manager\CollectionManagerInterface::getByKey PHP Method

getByKey() public method

Returns collection by key.
public getByKey ( string $key, string $locale ) : Collection
$key string
$locale string
return Sulu\Bundle\MediaBundle\Api\Collection
    public function getByKey($key, $locale);

Usage Example

示例#1
0
 /**
  * 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;
 }