@@ -33,13 +33,15 @@ public function register($category, $path, $mainContextId = null)
3333 $ success = parent ::register ($ category , $ path );
3434
3535 if ($ success && $ this ->getEnabled ()) {
36- $ this ->addTemplateFilters ();
36+ HookRegistry::register ('TemplateManager::display ' , [$ this , 'addScripts ' ]);
37+ HookRegistry::register ('TemplateManager::display ' , [$ this , 'addTemplateFilters ' ]);
38+ HookRegistry::register ('TemplateManager::display ' , [$ this , 'addMenu ' ]);
39+ HookRegistry::register ('LoadHandler ' , [$ this , 'addHandlers ' ]);
40+
3741 $ this ->addToSchema ();
3842 $ this ->addFormConfig ();
3943 $ this ->addEndpoints ();
40- $ this ->addScripts ();
4144 $ this ->addListeners ();
42- $ this ->addHandlers ();
4345 }
4446
4547 return $ success ;
@@ -115,21 +117,20 @@ public function manage($args, $request)
115117 return parent ::manage ($ args , $ request );
116118 }
117119
118- public function addTemplateFilters ()
120+ public function addTemplateFilters ($ hookName , $ args )
119121 {
120- HookRegistry::register ('TemplateManager::display ' , function ($ hookName , $ args ) {
121- $ templateMgr = $ args [0 ];
122- $ template = $ args [1 ];
122+ $ templateMgr = $ args [0 ];
123+ $ template = $ args [1 ];
123124
124- $ thothSectionFilter = new ThothSectionFilter ();
125- $ thothSectionFilter ->registerFilter ($ templateMgr , $ template , $ this );
126- });
125+ $ thothSectionFilter = new ThothSectionFilter ();
126+ $ thothSectionFilter ->registerFilter ($ templateMgr , $ template , $ this );
127127 }
128128
129129 public function addToSchema ()
130130 {
131131 $ thothSchema = new ThothSchema ();
132132 HookRegistry::register ('Schema::get::submission ' , [$ thothSchema , 'addWorkIdToSchema ' ]);
133+ HookRegistry::register ('Submission::getBackendListProperties::properties ' , [$ thothSchema , 'addToBackendProps ' ]);
133134 }
134135
135136 public function addFormConfig ()
@@ -144,22 +145,20 @@ public function addEndpoints()
144145 HookRegistry::register ('APIHandler::endpoints ' , [$ thothEndpoint , 'addEndpoints ' ]);
145146 }
146147
147- public function addScripts ()
148+ public function addScripts ($ hookName , $ args )
148149 {
149- HookRegistry::register ('TemplateManager::display ' , function ($ hookName , $ args ) {
150- $ templateMgr = $ args [0 ];
151- $ template = $ args [1 ];
152- $ request = Application::get ()->getRequest ();
153-
154- $ thothNotification = new ThothNotification ();
155- $ thothNotification ->addJavaScriptData ($ request , $ templateMgr );
156- $ thothNotification ->addJavaScript ($ request , $ templateMgr , $ this );
157-
158- $ thothSectionFilter = new ThothSectionFilter ();
159- $ thothSectionFilter ->addJavaScriptData ($ request , $ templateMgr , $ template );
160- $ thothSectionFilter ->addJavaScript ($ request , $ templateMgr , $ this );
161- $ thothSectionFilter ->addStyleSheet ($ request , $ templateMgr , $ this );
162- });
150+ $ templateMgr = $ args [0 ];
151+ $ template = $ args [1 ];
152+ $ request = Application::get ()->getRequest ();
153+
154+ $ thothNotification = new ThothNotification ();
155+ $ thothNotification ->addJavaScriptData ($ request , $ templateMgr );
156+ $ thothNotification ->addJavaScript ($ request , $ templateMgr , $ this );
157+
158+ $ thothSectionFilter = new ThothSectionFilter ();
159+ $ thothSectionFilter ->addJavaScriptData ($ request , $ templateMgr , $ template );
160+ $ thothSectionFilter ->addJavaScript ($ request , $ templateMgr , $ this );
161+ $ thothSectionFilter ->addStyleSheet ($ request , $ templateMgr , $ this );
163162 }
164163
165164 public function addListeners ()
@@ -172,16 +171,56 @@ public function addListeners()
172171 HookRegistry::register ('Publication::edit ' , [$ publicationEditListener , 'updateThothBook ' ]);
173172 }
174173
175- public function addHandlers ()
174+ public function addHandlers ($ hookName , $ args )
175+ {
176+ $ page = $ args [0 ];
177+ $ op = $ args [1 ];
178+
179+ if (!$ this ->getEnabled () || $ page !== 'thoth ' ) {
180+ return false ;
181+ }
182+
183+ if ($ op === 'register ' ) {
184+ $ this ->import ('controllers/modal/RegisterHandler ' );
185+ define ('HANDLER_CLASS ' , 'RegisterHandler ' );
186+ return true ;
187+ }
188+
189+ if ($ op === 'index ' ) {
190+ $ this ->import ('pages/thoth/ThothHandler ' );
191+ define ('HANDLER_CLASS ' , 'ThothHandler ' );
192+ return true ;
193+ }
194+
195+ return false ;
196+ }
197+
198+ public function addMenu ($ hookName , $ args )
176199 {
177- HookRegistry::register ('LoadHandler ' , function ($ hookName , $ args ) {
178- $ page = $ args [0 ];
179- if ($ this ->getEnabled () && $ page === 'thoth ' ) {
180- $ this ->import ('controllers/modal/RegisterHandler ' );
181- define ('HANDLER_CLASS ' , 'RegisterHandler ' );
182- return true ;
183- }
200+ $ templateMgr = $ args [0 ];
201+
202+ $ request = Application::get ()->getRequest ();
203+ $ router = $ request ->getRouter ();
204+ $ userRoles = (array ) $ router ->getHandler ()->getAuthorizedContextObject (ASSOC_TYPE_USER_ROLES );
205+
206+ $ menu = $ templateMgr ->getState ('menu ' );
207+
208+ if (empty ($ menu )) {
184209 return false ;
185- });
210+ }
211+
212+ if (in_array (ROLE_ID_MANAGER , $ userRoles )) {
213+ $ menu = array_slice ($ menu , 0 , 2 , true ) +
214+ [
215+ 'thoth ' => [
216+ 'name ' => __ ('plugins.generic.thoth.navigation.thoth ' ),
217+ 'url ' => $ router ->url ($ request , null , 'thoth ' ),
218+ 'isCurrent ' => $ router ->getRequestedPage ($ request ) === 'thoth ' ,
219+ ]
220+ ] +
221+ array_slice ($ menu , 2 , null , true );
222+ }
223+
224+ $ templateMgr ->setState (['menu ' => $ menu ]);
186225 }
187226}
0 commit comments