1111use wcf \data \IStorableObject ;
1212use wcf \data \language \item \LanguageItemList ;
1313use wcf \form \AbstractFormBuilderForm ;
14- use wcf \system \exception \NamedUserException ;
1514use wcf \system \form \builder \container \FormContainer ;
1615use wcf \system \form \builder \container \TabFormContainer ;
1716use wcf \system \form \builder \container \TabMenuFormContainer ;
@@ -60,6 +59,8 @@ class FaqQuestionAddForm extends AbstractFormBuilderForm
6059
6160 protected array $ multiLingualAnswers = [];
6261
62+ protected array $ categories ;
63+
6364 #[Override]
6465 public function readParameters ()
6566 {
@@ -102,31 +103,6 @@ protected function createForm()
102103 {
103104 parent ::createForm ();
104105
105- $ categoryTree = new FaqCategoryNodeTree ('dev.tkirch.wsc.faq.category ' );
106- $ categoryTree ->setMaxDepth (0 );
107- $ categoryList = $ categoryTree ->getIterator ();
108-
109- $ categories = [];
110- foreach ($ categoryList as $ category ) {
111- $ categories [$ category ->categoryID ] = $ category ;
112-
113- $ childCategories = $ category ->getAllChildCategories ();
114- if (!\count ($ childCategories )) {
115- continue ;
116- }
117-
118- foreach ($ childCategories as $ childCategory ) {
119- $ childCategory ->setPrefix ();
120- $ categories [$ childCategory ->categoryID ] = $ childCategory ;
121- }
122- }
123-
124- if (!\count ($ categories )) {
125- throw new NamedUserException (
126- WCF ::getLanguage ()->getDynamicVariable ('wcf.acp.faq.question.error.noCategory ' )
127- );
128- }
129-
130106 $ tabContent = [];
131107 if ($ this ->isMultilingual ) {
132108 foreach ($ this ->availableLanguages as $ language ) {
@@ -137,6 +113,7 @@ protected function createForm()
137113 ->label ('wcf.acp.faq.question.answer ' )
138114 ->messageObjectType ('dev.tkirch.wsc.faq.question ' )
139115 ->attachmentData ('dev.tkirch.wsc.faq.question ' )
116+ ->supportSmilies (true )
140117 ->required (),
141118 ]);
142119 }
@@ -148,7 +125,7 @@ protected function createForm()
148125 ->appendChildren ([
149126 SingleSelectionFormField::create ('categoryID ' )
150127 ->label ('wcf.acp.faq.category ' )
151- ->options ($ categories )
128+ ->options ($ this -> getCategories () )
152129 ->required (),
153130 TextFormField::create ('question ' )
154131 ->label ('wcf.acp.faq.question.question ' )
@@ -163,8 +140,8 @@ protected function createForm()
163140 : WysiwygFormContainer::create ('answer ' )
164141 ->label ('wcf.acp.faq.question.answer ' )
165142 ->messageObjectType ('dev.tkirch.wsc.faq.question ' )
166- // ->messageLanguageItemPattern('wcf.faq.question.answer\d+')
167143 ->attachmentData ('dev.tkirch.wsc.faq.question ' )
144+ ->supportSmilies (true )
168145 ->required ()
169146 ),
170147 FormContainer::create ('position ' )
@@ -239,4 +216,40 @@ protected function setFormAction()
239216
240217 $ this ->form ->action (LinkHandler::getInstance ()->getControllerLink (static ::class, $ parameters ));
241218 }
219+
220+ #[Override]
221+ public function assignVariables ()
222+ {
223+ parent ::assignVariables ();
224+
225+ WCF ::getTPL ()->assign ([
226+ 'categories ' => $ this ->getCategories (),
227+ ]);
228+ }
229+
230+ protected function getCategories (): array
231+ {
232+ if (!isset ($ this ->categories )) {
233+ $ categoryTree = new FaqCategoryNodeTree ('dev.tkirch.wsc.faq.category ' );
234+ $ categoryTree ->setMaxDepth (0 );
235+ $ categoryList = $ categoryTree ->getIterator ();
236+
237+ $ this ->categories = [];
238+ foreach ($ categoryList as $ category ) {
239+ $ this ->categories [$ category ->categoryID ] = $ category ;
240+
241+ $ childCategories = $ category ->getAllChildCategories ();
242+ if (!\count ($ childCategories )) {
243+ continue ;
244+ }
245+
246+ foreach ($ childCategories as $ childCategory ) {
247+ $ childCategory ->setPrefix ();
248+ $ this ->categories [$ childCategory ->categoryID ] = $ childCategory ;
249+ }
250+ }
251+ }
252+
253+ return $ this ->categories ;
254+ }
242255}
0 commit comments