コード例 #1
0
ファイル: ToMany.php プロジェクト: kuba1999/DoctrineForms
 /**
  * {@inheritdoc}
  */
 public function save(ClassMetadata $meta, Component $component, $entity)
 {
     if (!$component instanceof ToManyContainer) {
         return FALSE;
     }
     if (!($collection = $this->getCollection($meta, $entity, $component->getName()))) {
         return FALSE;
     }
     $em = $this->mapper->getEntityManager();
     $class = $meta->getAssociationTargetClass($component->getName());
     $relationMeta = $em->getClassMetadata($class);
     /** @var Nette\Forms\Container $container */
     foreach ($component->getComponents(FALSE, 'Nette\\Forms\\Container') as $container) {
         $isNew = substr($container->getName(), 0, strlen(ToManyContainer::NEW_PREFIX)) === ToManyContainer::NEW_PREFIX;
         $name = $isNew ? substr($container->getName(), strlen(ToManyContainer::NEW_PREFIX)) : $container->getName();
         if (!($relation = $collection->get($name))) {
             // entity was added from the client
             if (!$component->isAllowedRemove()) {
                 continue;
             }
             $collection[$name] = $relation = $relationMeta->newInstance();
         }
         $this->mapper->save($relation, $container);
     }
     return TRUE;
 }