/** * Article form factory. * * @return \Nette\Application\UI\Form */ protected function createComponentArticleForm() { $form = BaseFormRenderer::factory(); $form->addText('title', 'Title:')->setRequired('Please enter title.'); $form->addTextArea('content', 'Content:')->setHtmlId('code')->setRequired('Please enter content.'); $languages = array('cs' => 'česky', 'en' => 'english'); $form->addSelect('language', 'Language:', $languages); $types = $this->articleManager->getArticleTypes(); if (!empty($types)) { $form->addSelect('type', 'Type', $types); } else { $form->addHidden('type', 'default'); } // TODO : use class name? $form->addText('tags', 'Tags:')->setAttribute('data-tags-default', $this->articleManager->getTagsAsString())->setAttribute("style", 'width:100%')->setHtmlId('tags'); if (!empty($this->article)) { $tags = $this->articleManager->getTagsAsStringForArticle($this->article->id); $defaults = ['title' => $this->article->title, 'content' => $this->article->content, 'tags' => $tags, 'language' => $this->article->language]; $form->setDefaults($defaults); if (!empty($types)) { $type = $this->articleManager->getArticleType($this->article->id); if ($type) { $form->setDefaults(['type' => $type->name]); } } $form->addSubmit('send', 'Save article'); } else { $form->addSubmit('send', 'Add article'); } $form->onSuccess[] = $this->articleFormSucceeded; return $form; }
public function beforeRender() { parent::beforeRender(); $this->template->defaultTags = $this->articleManager->getTagsAsString(); }