public function load(ObjectManager $manager) { $tag = new Tag(); $tag->setName('name'); $manager->persist($tag); $manager->flush(); self::$tags[] = $tag; }
/** * {@inheritDoc} */ public function load(ObjectManager $manager) { $faker = \Faker\Factory::create('pl_PL'); for ($a = 0; $a < self::SIZE; $a++) { $tag = new Tag(); $tag->setName($faker->word); $tag->addPost($this->getReference(sprintf('tag-post-%d', rand(0, LoadCommentPostData::MAX_SIZE - 1)))); $manager->persist($tag); } $manager->flush(); }
/** * * @param string $string String to transform * * @return Tag $tag * */ public function reverseTransform($string) { $tags = new \Doctrine\Common\Collections\ArrayCollection(); $arrayOfTags = explode(",", $string); foreach ($arrayOfTags as $nameOfTag) { $result = $this->om->getRepository('AcmeBlogBundle:Tag')->findOneByName($nameOfTag); if (!$result) { //Action when tag don't exist $tag = new Tag(); $tag->setName($nameOfTag); $tags->add($tag); } else { $tags->add($result); } } return $tags; }
/** * Add tags * * @param \Acme\BlogBundle\Entity\Tag $tags * @return User */ public function addTag(\Acme\BlogBundle\Entity\Tag $tags) { $tags->addUser($this); $this->tags[] = $tags; return $this; }