I'm developing a plugin that adds a menu icon to Moodle's navigation bar (left of the notifications & messages menus, in v3). The best way I could find to add it was with jQuery, using myplugin_extend_navigation() as a trigger to run:
$PAGE->requires->js_call_amd('myplugin/myjscode', 'init', array($myparam))
That seems to work fine for me, but this context seems to be restricting what I want to do next.
I'd like the menu to be rendered differently for admin users, vs. student or teacher users. Since there isn't a simple isAdmin property to check, I've used the Access API to check the permissions on an action that I assume only admins can take. This code has been working in my dev environment:
$isAdmin = has_capability('moodle/site:manageblocks', context_module::instance(1) );
The problem is that not every environment will have a context module with the ID 1. So, I started looking for ways to check for valid module IDs. A module can get the $cm argument from _extend_navigation(), but a local plugin only gets $nav. $PAGE->cm is also empty.
Are there other options to identify admin users in this case? Thanks in advance.