1414 */
1515
1616import ('plugins.generic.thoth.classes.facades.ThothService ' );
17+ import ('plugins.generic.thoth.classes.ThothValidator ' );
1718
1819class ThothRegister
1920{
@@ -35,9 +36,8 @@ public function addWorkIdToSchema($hookName, $args)
3536 return false ;
3637 }
3738
38- public function addImprintField ($ hookName , $ form )
39+ public function addThothField ($ hookName , $ form )
3940 {
40-
4141 if ($ form ->id !== 'publish ' || !empty ($ form ->errors )) {
4242 return ;
4343 }
@@ -48,48 +48,63 @@ public function addImprintField($hookName, $form)
4848 return ;
4949 }
5050
51+ $ errors = [];
52+
5153 try {
5254 $ thothClient = $ this ->plugin ->getThothClient ($ submission ->getData ('contextId ' ));
5355 $ publishers = $ thothClient ->linkedPublishers ();
5456 $ imprints = $ thothClient ->imprints (['publishers ' => array_column ($ publishers , 'publisherId ' )]);
57+ } catch (ThothException $ e ) {
58+ $ errors [] = __ ('plugins.generic.thoth.connectionError ' );
59+ error_log ($ e ->getMessage ());
60+ }
5561
56- $ imprintOptions = [];
57- foreach ($ imprints as $ imprint ) {
58- $ imprintOptions [] = [
59- 'value ' => $ imprint ['imprintId ' ],
60- 'label ' => $ imprint ['imprintName ' ]
61- ];
62- }
62+ if (empty ($ errors )) {
63+ $ errors = ThothValidator::validate ($ submission );
64+ }
6365
64- $ form ->addField (new \PKP \components \forms \FieldOptions ('registerConfirmation ' , [
65- 'label ' => __ ('plugins.generic.thoth.register.label ' ),
66- 'options ' => [
67- ['value ' => true , 'label ' => __ ('plugins.generic.thoth.register.confirmation ' )]
68- ],
69- 'value ' => false ,
70- 'groupId ' => 'default ' ,
71- ]))
72- ->addField (new \PKP \components \forms \FieldSelect ('imprint ' , [
73- 'label ' => __ ('plugins.generic.thoth.imprint ' ),
74- 'options ' => $ imprintOptions ,
75- 'required ' => true ,
76- 'showWhen ' => 'registerConfirmation ' ,
77- 'groupId ' => 'default ' ,
78- 'value ' => $ imprints [0 ]['imprintId ' ] ?? null
79- ]));
80- } catch (ThothException $ e ) {
81- $ warningIconHtml = '<span class="fa fa-exclamation-triangle pkpIcon--inline"></span> ' ;
82- $ noticeMsg = __ ('plugins.generic.thoth.connectionError ' );
83- $ msg = '<div class="pkpNotification pkpNotification--warning"> ' . $ warningIconHtml . $ noticeMsg . '</div> ' ;
66+ if (!empty ($ errors )) {
67+ $ msg = '<div class="pkpNotification pkpNotification--warning"> ' ;
68+ $ msg .= __ ('plugins.generic.thoth.register.warning ' );
69+ $ msg .= '<ul> ' ;
70+ foreach ($ errors as $ error ) {
71+ $ msg .= '<li> ' . $ error . '</li> ' ;
72+ }
73+ $ msg .= '</ul></div> ' ;
8474
8575 $ form ->addField (new \PKP \components \forms \FieldHTML ('registerNotice ' , [
8676 'description ' => $ msg ,
8777 'groupId ' => 'default ' ,
8878 ]));
8979
90- error_log ( $ e -> getMessage ()) ;
80+ return false ;
9181 }
9282
83+ $ imprintOptions = [];
84+ foreach ($ imprints as $ imprint ) {
85+ $ imprintOptions [] = [
86+ 'value ' => $ imprint ['imprintId ' ],
87+ 'label ' => $ imprint ['imprintName ' ]
88+ ];
89+ }
90+
91+ $ form ->addField (new \PKP \components \forms \FieldOptions ('registerConfirmation ' , [
92+ 'label ' => __ ('plugins.generic.thoth.register.label ' ),
93+ 'options ' => [
94+ ['value ' => true , 'label ' => __ ('plugins.generic.thoth.register.confirmation ' )]
95+ ],
96+ 'value ' => false ,
97+ 'groupId ' => 'default ' ,
98+ ]))
99+ ->addField (new \PKP \components \forms \FieldSelect ('imprint ' , [
100+ 'label ' => __ ('plugins.generic.thoth.imprint ' ),
101+ 'options ' => $ imprintOptions ,
102+ 'required ' => true ,
103+ 'showWhen ' => 'registerConfirmation ' ,
104+ 'groupId ' => 'default ' ,
105+ 'value ' => $ imprints [0 ]['imprintId ' ] ?? null
106+ ]));
107+
93108 return false ;
94109 }
95110
0 commit comments