/** * @param RZ\Roadiz\Core\Entities\DocumentTranslation $document * * @return \Symfony\Component\Form\Form */ private function buildEditForm(DocumentTranslation $document) { $defaults = ['name' => $document->getName(), 'description' => $document->getDescription(), 'copyright' => $document->getCopyright()]; $builder = $this->createFormBuilder($defaults)->add('name', 'text', ['label' => 'name', 'required' => false])->add('description', new \RZ\Roadiz\CMS\Forms\MarkdownType(), ['label' => 'description', 'required' => false])->add('copyright', 'text', ['label' => 'copyright', 'required' => false]); return $builder->getForm(); }
/** * Create a Document from an embed media * * @param Pimple\Container $container description * * @return Document */ public function createDocumentFromFeed(Container $container) { $url = $this->downloadThumbnail(); if (!$this->exists()) { throw new \Exception('no.embed.document.found'); } if (false !== $url) { $existingDocument = $container['em']->getRepository('RZ\\Roadiz\\Core\\Entities\\Document')->findOneBy(['filename' => $url]); } else { $existingDocument = $container['em']->getRepository('RZ\\Roadiz\\Core\\Entities\\Document')->findOneBy(['embedId' => $this->embedId, 'embedPlatform' => static::$platform]); } if (null !== $existingDocument) { throw new EntityAlreadyExistsException('embed.document.already_exists'); } $document = new Document(); $document->setEmbedId($this->embedId); $document->setEmbedPlatform(static::$platform); if (false !== $url) { /* * Move file from documents file root to its folder. */ $document->setFilename($url); $document->setMimeType('image/jpeg'); if (!file_exists(Document::getFilesFolder() . '/' . $document->getFolder())) { mkdir(Document::getFilesFolder() . '/' . $document->getFolder()); } rename(Document::getFilesFolder() . '/' . $url, $document->getAbsolutePath()); } $container['em']->persist($document); /* * Create document metas * for each translation */ $translations = $container['em']->getRepository('RZ\\Roadiz\\Core\\Entities\\Translation')->findAll(); foreach ($translations as $translation) { $documentTr = new DocumentTranslation(); $documentTr->setDocument($document); $documentTr->setTranslation($translation); $documentTr->setName($this->getMediaTitle()); $documentTr->setDescription($this->getMediaDescription()); $documentTr->setCopyright($this->getMediaCopyright()); $container['em']->persist($documentTr); } $container['em']->flush(); return $document; }