Custom Nav Links: find menu index

Got something cool to share with AppGini users? Feel free to post it here!
Post Reply
User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Custom Nav Links: find menu index

Post by jsetzer » 2023-03-26 09:04

For those of you adding custom menu items to existing menus:

You probably know the problems with shifting menu indexes depending on permissions on tables when adding a custom menu item:
Screenshot_20230326_105951_Chrome.jpg
Screenshot_20230326_105951_Chrome.jpg (46.03 KiB) Viewed 1175 times
Screenshot_20230326_110057_Chrome.jpg
Screenshot_20230326_110057_Chrome.jpg (83.47 KiB) Viewed 1175 times

I have written a short PHP function for automatically finding the correct menu index:

https://appgini.bizzworxx.de/appgini/cu ... able-name/

With this function, custom menu items will be placed in the right menu even if menus before are not rendered due to permissions.
Screenshot_20230326_105707_Twitter.jpg
Screenshot_20230326_105707_Twitter.jpg (148.15 KiB) Viewed 1175 times
TL;DR

Code: Select all

function getTableGroupIndexByTableName($tn, $default = null)
{
  $i = 0;
  foreach (get_table_groups(false) as $tgc => $tns) {
    if (in_array($tn, $tns)) return $i;
    $i++;
  }
  return $default;
}
I hope it will help someone.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

Post Reply