Ejemplo n.º 1
0
 /**
  * @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();
 }