Forum

Thread tagged as: Question, Api, Add-on-development

Getting menu into admin header for editors

I am having some trouble with editing my own app using the API. I have it getting items into the admin menu under apps. But then it wasn't appearing for editors, so wonder where to start. I have a permission in the system which I can check under roles, but how do I link this directly to the navigation? Also, it appears I accidentally changed the text for 'Apps' to my custom apps title, so if you know the obvious place I may have done this before I go through my git diff, that would be great.

Dan Duke

Dan Duke 1 points

  • 6 years ago
Rachel Andrew

Rachel Andrew 394 points
Perch Support

You would use Settings https://docs.grabaperch.com/api/app-settings/

To help further we would need to see your code.

Which part of my app code would help? Ultimately I just want to add a menu item so editors can see, so would have thought there a single line I add in somewhere which sites within the ->priv() if statement.

In my addon I have this line, which is creating the priviledge I would like to use: $UserPrivileges->create_privilege('fareshare_supermarkets.manage', 'Manage supermarkets');

It is there, and I can check it accordingly. So I would like, when checked for editor, for 'Supermarkets' to appear next to 'Pages' for users with that role

Maybe the best way for what I want is to enable the dashboard and just create a widget that links to the page(s) they need to get to instead

Drew McLellan

Drew McLellan 2638 points
Perch Support

Can you show us your admin.php file?

This is about it right now, I imagine I would add in the if statement once I get the item in the menu.

<?php
$this->register_app('fareshare_supermarkets', 'Supermarkets', 1, 'Supermarket editable UI', '1.0');
$this->add_create_page('fareshare_supermarkets', 'edit');

FYI the widget approach also appears to be working nicely, and using the if statement with permissions set

Drew McLellan

Drew McLellan 2638 points
Perch Support

So it's this that registers the app and adds it to the Apps menu:

$this->register_app('fareshare_supermarkets', 'Supermarkets', 1, 'Supermarket editable UI', '1.0');

If you want to check a priv first, just wrap it:

if ($CurrentUser->logged_in() && $CurrentUser->has_priv('fareshare_supermarkets.manage')) {
    $this->register_app('fareshare_supermarkets', 'Supermarkets', 1, 'Supermarket editable UI', '1.0');
    $this->add_create_page('fareshare_supermarkets', 'edit');
}

Sure I get that part. But at the moment, even without the if statement, nothing appears in the admin menu for my editor role. Should it automatically appear then for them? Or is there an over-arching permission they need which gives them access to all apps?

Note that my admin role does see supermarkets appear under the app menu

Drew McLellan

Drew McLellan 2638 points
Perch Support

No, if you're not restricting access then everyone should have access.