예제 #1
0
파일: Collection.php 프로젝트: sulu/sulu
 /**
  * @param bool $create
  *
  * @return CollectionMeta
  */
 private function getMeta($create = false)
 {
     $locale = $this->locale;
     $metaCollection = $this->entity->getMeta();
     // get meta only with this locale
     $metaCollectionFiltered = $metaCollection->filter(function ($meta) use($locale) {
         /** @var CollectionMeta $meta */
         if ($meta->getLocale() == $locale) {
             return true;
         }
         return false;
     });
     // check if meta was found
     if ($metaCollectionFiltered->isEmpty()) {
         if ($create) {
             // create when not found
             $meta = new CollectionMeta();
             $meta->setLocale($this->locale);
             $meta->setCollection($this->entity);
             $this->entity->addMeta($meta);
             return $meta;
         }
         // return first when create false
         return $this->entity->getDefaultMeta();
     }
     // return exists
     return $metaCollectionFiltered->first();
 }