public function load(ObjectManager $manager) { $this->manager = $manager; //example of initial fixture for the resource entity $sr = new SimuResource(); $sr->setField('bunny'); $sr->setOtherfield(16); $sr->setOtherfield2(28); $this->manager->persist($sr); $this->manager->flush(); }
/** * @DI\Observe("copy_cpasimusante_simuresource") * * @param CopyResourceEvent $event */ public function onCopy(CopyResourceEvent $event) { $em = $this->container->get('doctrine.orm.entity_manager'); $resource = $event->getResource(); //Retrieve the entity (as an object) from the repository $resourceNow = $em->getRepository('CPASimUSanteSimuResourceBundle:SimuResource')->find($resource->getId()); //Copy the entity into a new one $resourceNew = new SimuResource(); //custom entity fields $resourceNew->setField($resourceNow->getField()); $resourceNew->setOtherfield($resourceNow->getOtherfield()); //generic entity fields $resourceNew->setName($resourceNow->getName()); //Save the entity $em->persist($resourceNew); $em->flush(); //Set the copy (Claroline stuff) $event->setCopy($resourceNew); $event->stopPropagation(); }