Hello
I have a local plugin + settings page and I need a person other than admin with a capability x granted at system level to be able to view it.
I have followed the advice given here https://moodle.org/mod/forum/discuss.php?d=376316 except I had to change 'root' in this line to be 'localplugins' in order for it to show (even to admin).
$ADMIN->add('root', new admin_category('local_myplugin', new lang_string('pluginname', 'local_myplugin')));
Here is my code:
$systemcontext = context_system::instance();
$ismanager = has_capability('local/myplugin:dosomething', $systemcontext);
if ($hassiteconfig || $ismanager)
{
$ADMIN->add('localplugins', new admin_category('local_myplugin', new lang_string('pluginname', 'local_myplugin')));
$ADMIN->add('local_myplugin', new admin_externalpage('mypluginsettings', new lang_string('mypluginsettings', 'local_myplugin'), new moodle_url('/local/pluginname/mypluginsettings.php'),'local/myplugin:dosomething'));
}
$capabilities = array(
'local/myplugin:dosomething' => [
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'archetypes' => array(
'manager' => CAP_ALLOW
)
]
);
It is recognising that the testuser has the capability but neither the category nor page are visible to this person. (It is a role with archetype Manager that has this capability allowed, and the role is assigned at system level).
A few questions,
- any idea why it is not working? (Moodle 3.9)
- does it always have to be an admin_externalpage to make it work with a defined capability?
- if 2, does this mean the usual settings page syntax cannot be used and I have to revert to an mform?
Best wishes
Jo