@@ -41,6 +41,8 @@ public function register($category, $path, $mainContextId = null)
4141
4242 if ($ success && $ this ->getEnabled ($ mainContextId )) {
4343 Hook::add ('Form::config::after ' , [$ this , 'editFormComponents ' ]);
44+ Hook::add ('preprintgalleyform::display ' , [$ this , 'modifyGalleyForm ' ]);
45+ Hook::add ('preprintgalleyform::validate ' , [$ this , 'modifyGalleyFormValidation ' ]);
4446 Hook::add ('TemplateManager::display ' , [$ this , 'modifySubmissionSteps ' ]);
4547 Hook::add ('Submission::validateSubmit ' , [$ this , 'validateSubmissionFields ' ]);
4648 Hook::add ('Template::SubmissionWizard::Section::Review ' , [$ this , 'modifyReviewSections ' ]);
@@ -164,6 +166,52 @@ private function removePrefixAndSubtitleFields($formConfig)
164166 return $ formConfig ;
165167 }
166168
169+ public function modifyGalleyForm ($ hookName , $ params )
170+ {
171+ $ request = Application::get ()->getRequest ();
172+ $ templateMgr = TemplateManager::getManager ($ request );
173+
174+ $ templateMgr ->registerFilter ("output " , [$ this , 'removeFieldsFromGalleyFormFilter ' ]);
175+ }
176+
177+ public function removeFieldsFromGalleyFormFilter ($ output , $ templateMgr )
178+ {
179+ if (preg_match ('/id="preprintGalleyForm"/ ' , $ output )) {
180+ preg_match ('/<\/form>/ ' , $ output , $ matches , PREG_OFFSET_CAPTURE );
181+
182+ $ posMatch = $ matches [0 ][1 ];
183+ $ removeGalleyFields = $ templateMgr ->fetch ($ this ->getTemplateResource ('removeGalleyFields.tpl ' ));
184+ $ output = substr_replace ($ output , $ removeGalleyFields , $ posMatch , 0 );
185+
186+ $ templateMgr ->unregisterFilter ('output ' , array ($ this , 'removeFieldsFromGalleyFormFilter ' ));
187+ }
188+
189+ return $ output ;
190+ }
191+
192+ public function modifyGalleyFormValidation ($ hookName , $ params )
193+ {
194+ $ form = &$ params [0 ];
195+ $ submission = $ form ->_submission ;
196+
197+ if (!empty ($ submission ->getData ('submissionProgress ' )) || !empty ($ form ->_preprintGalley )) {
198+ return Hook::CONTINUE ;
199+ }
200+
201+ $ checker = new ScreeningChecker ();
202+ $ galleys = $ submission ->getGalleys ();
203+ $ galleysFiletypes = array_map (function ($ galley ) {
204+ return ($ galley ->getFileType ());
205+ }, $ galleys );
206+
207+ if ($ checker ->checkNumberPdfs ($ galleysFiletypes )[0 ]) {
208+ $ form ->addErrorField ('preprintGalleyFormNotification ' );
209+ $ form ->addError ('preprintGalleyFormNotification ' , __ ("plugins.generic.scieloScreening.screeningRules.numPdfs " ));
210+ }
211+
212+ return Hook::CONTINUE ;
213+ }
214+
167215 public function modifySubmissionSteps ($ hookName , $ params )
168216 {
169217 $ request = Application::get ()->getRequest ();
0 commit comments