1010
1111namespace Joomla \Module \Menu \Site \Helper ;
1212
13+ use Joomla \CMS \Application \CMSApplicationInterface ;
1314use Joomla \CMS \Cache \CacheControllerFactoryInterface ;
1415use Joomla \CMS \Cache \Controller \OutputController ;
1516use Joomla \CMS \Factory ;
1617use Joomla \CMS \Language \Multilanguage ;
1718use Joomla \CMS \Router \Route ;
19+ use Joomla \Registry \Registry ;
1820
1921// phpcs:disable PSR1.Files.SideEffects
2022\defined ('_JEXEC ' ) or die;
@@ -30,20 +32,20 @@ class MenuHelper
3032 /**
3133 * Get a list of the menu items.
3234 *
33- * @param \Joomla\Registry\Registry &$params The module options.
35+ * @param Registry &$params The module options.
36+ * @param CMSApplicationInterface $app The application
3437 *
3538 * @return array
3639 *
37- * @since 1.5
40+ * @since __DEPLOY_VERSION__
3841 */
39- public static function getList ( &$ params)
42+ public function getItems ( Registry &$ params, CMSApplicationInterface $ app ): array
4043 {
41- $ app = Factory::getApplication ();
4244 $ menu = $ app ->getMenu ();
4345
4446 // Get active menu item
45- $ base = self :: getBase ($ params );
46- $ levels = Factory:: getUser ()->getAuthorisedViewLevels ();
47+ $ base = $ this -> getBaseItem ($ params, $ app );
48+ $ levels = $ app -> getIdentity ()->getAuthorisedViewLevels ();
4749 asort ($ levels );
4850
4951 // Compose cache key
@@ -136,7 +138,7 @@ public static function getList(&$params)
136138
137139 // Get the language of the target menu item when site is multilingual
138140 if (Multilanguage::isEnabled ()) {
139- $ newItem = Factory:: getApplication () ->getMenu ()->getItem ((int ) $ itemParams ->get ('aliasoptions ' ));
141+ $ newItem = $ app ->getMenu ()->getItem ((int ) $ itemParams ->get ('aliasoptions ' ));
140142
141143 // Use language code if not set to ALL
142144 if ($ newItem != null && $ newItem ->language && $ newItem ->language !== '* ' ) {
@@ -183,24 +185,25 @@ public static function getList(&$params)
183185 /**
184186 * Get base menu item.
185187 *
186- * @param \Joomla\Registry\Registry &$params The module options.
188+ * @param Registry &$params The module options.
189+ * @param CMSApplicationInterface $app The application
187190 *
188191 * @return object
189192 *
190- * @since 3.0.2
193+ * @since __DEPLOY_VERSION__
191194 */
192- public static function getBase ( &$ params)
195+ public function getBaseItem ( Registry &$ params, CMSApplicationInterface $ app ): object
193196 {
194197 // Get base menu item from parameters
195198 if ($ params ->get ('base ' )) {
196- $ base = Factory:: getApplication () ->getMenu ()->getItem ($ params ->get ('base ' ));
199+ $ base = $ app ->getMenu ()->getItem ($ params ->get ('base ' ));
197200 } else {
198201 $ base = false ;
199202 }
200203
201204 // Use active menu item if no base found
202205 if (!$ base ) {
203- $ base = self :: getActive ( $ params );
206+ $ base = $ this -> getActiveItem ( $ app );
204207 }
205208
206209 return $ base ;
@@ -209,33 +212,114 @@ public static function getBase(&$params)
209212 /**
210213 * Get active menu item.
211214 *
212- * @param \Joomla\Registry\Registry &$params The module options.
215+ * @param CMSApplicationInterface $app The application
213216 *
214217 * @return object
215218 *
216- * @since 3.0.2
219+ * @since __DEPLOY_VERSION__
217220 */
218- public static function getActive (& $ params )
221+ public function getActiveItem ( CMSApplicationInterface $ app ): object
219222 {
220- $ menu = Factory:: getApplication () ->getMenu ();
223+ $ menu = $ app ->getMenu ();
221224
222- return $ menu ->getActive () ?: self :: getDefault ( );
225+ return $ menu ->getActive () ?: $ this -> getDefaultItem ( $ app );
223226 }
224227
225228 /**
226229 * Get default menu item (home page) for current language.
227230 *
231+ * @param CMSApplicationInterface $app The application
232+ *
228233 * @return object
234+ *
235+ * @since __DEPLOY_VERSION__
229236 */
230- public static function getDefault ()
237+ public function getDefaultItem ( CMSApplicationInterface $ app ): object
231238 {
232- $ menu = Factory:: getApplication () ->getMenu ();
239+ $ menu = $ app ->getMenu ();
233240
234241 // Look for the home menu
235242 if (Multilanguage::isEnabled ()) {
236- return $ menu ->getDefault (Factory:: getLanguage ()->getTag ());
243+ return $ menu ->getDefault ($ app -> getLanguage ()->getTag ());
237244 }
238245
239246 return $ menu ->getDefault ();
240247 }
248+
249+
250+ /**
251+ * Get a list of the menu items.
252+ *
253+ * @param Registry &$params The module options.
254+ *
255+ * @return array
256+ *
257+ * @since 1.5
258+ *
259+ * @deprecated __DEPLOY_VERSION__ will be removed in 7.0
260+ * Use the non-static method getItems
261+ * Example: Factory::getApplication()->bootModule('mod_menu', 'site')
262+ * ->getHelper('MenuHelper')
263+ * ->getItems($params, $app)
264+ */
265+ public static function getList (&$ params )
266+ {
267+ return (new self ())->getItems ($ params , Factory::getApplication ());
268+ }
269+
270+ /**
271+ * Get base menu item.
272+ *
273+ * @param Registry &$params The module options.
274+ *
275+ * @return object
276+ *
277+ * @since 3.0.2
278+ *
279+ * @deprecated __DEPLOY_VERSION__ will be removed in 7.0
280+ * Use the non-static method getBaseItem
281+ * Example: Factory::getApplication()->bootModule('mod_menu', 'site')
282+ * ->getHelper('MenuHelper')
283+ * ->getBaseItem($params, $app)
284+ */
285+ public static function getBase (&$ params )
286+ {
287+ return (new self ())->getBaseItem ($ params , Factory::getApplication ());
288+ }
289+
290+ /**
291+ * Get active menu item.
292+ *
293+ * @param Registry &$params The module options.
294+ *
295+ * @return object
296+ *
297+ * @since 3.0.2
298+ *
299+ * @deprecated __DEPLOY_VERSION__ will be removed in 7.0
300+ * Use the non-static method getActiveItem
301+ * Example: Factory::getApplication()->bootModule('mod_menu', 'site')
302+ * ->getHelper('MenuHelper')
303+ * ->getActiveItem($app)
304+ */
305+ public static function getActive (&$ params )
306+ {
307+ return (new self ())->getActiveItem (Factory::getApplication ());
308+ }
309+
310+ /**
311+ * Get default menu item (home page) for current language.
312+ *
313+ * @return object
314+ *
315+ * @deprecated __DEPLOY_VERSION__ will be removed in 7.0
316+ * Use the non-static method getDefaultItem
317+ * Example: Factory::getApplication()->bootModule('mod_menu', 'site')
318+ * ->getHelper('MenuHelper')
319+ * ->getDefaultItem($app)
320+ */
321+ public static function getDefault ()
322+ {
323+ return (new self ())->getDefaultItem (Factory::getApplication ());
324+ }
241325}
0 commit comments